我有两列我想要数据但是当我使用时:
SELECT rank, points FROM game
我得到这样的一切:
Rank | Points
rank_1 | 10
rank_2 | 5
rank_3 | 20
rank_1 | 5
rank_1 | 6
rank_2 | 4
我无法弄清楚如何将具有相同排名的所有人分组到一行中,并将所有个人点分组为一行。 像这样:
Rank | Points
rank_1 | 21
rank_2 | 9
rank_3 | 20
所以我可以看到哪个等级的总分最多。
答案 0 :(得分:3)
这是一个非常基本的GROUP BY
SUM()
:
Select Rank, Sum(Points) As Points
From Game
Group by Rank
答案 1 :(得分:1)
SELECT rank, SUM(points) FROM game GROUP BY rank
答案 2 :(得分:0)
Select [rank], sum(points) as points
from game
group by [rank]
order by sum(points) desc;