所以我有一个包含5列的表格:id, user_id, news_id, comment and date
。每次用户在新闻的评论区域上张贴内容时,数据都会插入到此表中。
现在,我正在尝试创建一个顶部海报功能,以显示发表评论最多的人。
我想知道如何根据该表中存在user_id的次数从该表中排序结果。
例如:
1 - 134(user_id) -> 20 posts(that's how many times this user_id was found in the table.)
2 - 123 -> 19
3 - 168 -> 15
等等。
提前致谢。
最佳答案
SELECT user_id, COUNT (*) as comments
FROM table
GROUP BY user_id
ORDER BY comments DESC
关于sql - SQL-按行数排序?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7841593/