dsf45346 2013-03-26 21:20
浏览 64
已采纳

如何在不进行多次查询的情况下从表中获取数据总和?

I am currently running this query:

SELECT *, COUNT(name) AS ActionCount 
FROM plays 
GROUP BY name 
ORDER BY ActionCount DESC LIMIT 0, 50

To select the most prominent/common names in a game of mine, how would I also get the total sum of the mileage every player drove through without running a query for every one of the 50 users selected above assuming I have a 'mileage' field in every game.

  • 写回答

1条回答 默认 最新

  • duanhui1869 2013-03-26 21:34
    关注

    I would have expected that:

    SELECT 
      *, 
      COUNT(name) AS ActionCount,
      SUM(mileage) AS totalMileage 
    FROM plays 
    GROUP BY name
    ORDER BY ActionCount DESC LIMIT 0, 50
    

    Would do it.

    It doesn't seem particularly tricky to me?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HC32L176调试了一个通过TIMER5+DMA驱动WS2812B
  • ¥15 三菱FX系列PLC串口指令
  • ¥15 cocos的js代码调用wx.createUseInfoButton问题!
  • ¥15 关于自相关函数法和周期图法实现对随机信号的功率谱估计的matlab程序运行的问题,请各位专家解答!
  • ¥15 Python程序,深度学习,有偿私
  • ¥15 扫描枪扫条形码出现问题
  • ¥35 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型