我有一个包含以下列的表:
+----+--------+-----+------+-------+-------+-------+
| Id | Member | End | Done | Right | Wrong | Score |
+----+--------+-----+------+-------+-------+-------+
每个会员都有几个条目。
我想选择每个会员得分的SUM()排序的一些(二十)行。
我试过了:
SELECT * FROM Challenge ORDER BY SUM(Score) LIMIT 20;
答案 0 :(得分:0)
您想要GROUP BY成员,然后您可以SUM
每个成员的分数。此查询执行您想要的操作(按第二个字段排序 - 总和 - 以DESC
顺序排列)
SELECT Member, SUM(Score)
FROM Challenge
GROUP BY Member
ORDER BY 2 DESC
LIMIT 20