我的目标是得到每个人的积分总和,并返回用户名和他/她的总积分。
id | username | points
1 Michelle 23
2 Chester 44
3 Michelle 13
4 Chester 23
5 Chester 65
6 Chester 43
7 Michelle 65
8 Chester 12
9 Michelle 54
10 Chester 76
欲望结果
username | total_points
Chester | total points of Chester
Michelle | total points of Michelle
答案 0 :(得分:0)
怎么样:
SELECT username, SUM(points) total_points
FROM mytable
GROUP BY username
ORDER BY username