[英]SQL: Count the values of a column per record
I am stuck on creating a query. 我坚持创建一个查询。
I got a table "videos" with this structure: 我得到了一个具有这种结构的表“视频”:
id | artist | song | hits
records are like: 记录如下:
1 | Rihanna | Song1 | 400
2 | Rihanna | Song2 | 100
3 | Prince | Song45 | 300
4 | The Police | Song456 | 1000
This is my non-working query: 这是我的非工作查询:
SELECT DISTINCT artist, SUM(hits)
FROM videos
ORDER BY hits DESC
The result is: 结果是:
Rihanna | 1800
But I'd like a result like this: 但我想要一个像这样的结果:
Rihanna | 500
Prince | 300
The Police | 1000
What am I doing wrong here? 我在这做错了什么?
SELECT artist, SUM(hits) as hitscount
FROM videos
GROUP BY artist
ORDER BY hitscount DESC
added suggestions from the comments. 从评论中添加了建议。 thanks!
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.