我被困在创建查询。
我得到了具有以下结构的表格“视频”:
id | artist | song | hits
记录如下:
1 | Rihanna | Song1 | 400
2 | Rihanna | Song2 | 100
3 | Prince | Song45 | 300
4 | The Police | Song456 | 1000
这是我不工作的查询:
SELECT DISTINCT artist, SUM(hits)
FROM videos
ORDER BY hits DESC
结果是:
Rihanna | 1800
但我想要这样的结果:
Rihanna | 500
Prince | 300
The Police | 1000
我在这里做错了什么?
SELECT artist, SUM(hits) as hitscount
FROM videos
GROUP BY artist
ORDER BY hitscount DESC
从评论中添加了建议。谢谢!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句