我目前正在运行此查询:
SELECT *, COUNT(name) AS ActionCount
FROM plays
GROUP BY name
ORDER BY ActionCount DESC LIMIT 0, 50
为了在我的游戏中选择最突出/最常见的名字,我怎么能得到每个玩家开车的里程总和,而不会对上面选择的50个用户中的每一个运行查询,假设我有''每场比赛的里程数。
答案 0 :(得分:3)
我原以为:
SELECT
*,
COUNT(name) AS ActionCount,
SUM(mileage) AS totalMileage
FROM plays
GROUP BY name
ORDER BY ActionCount DESC LIMIT 0, 50
会这样做。
对我来说这似乎并不特别棘手?