在 MySQL 数据库表评论中,有超过 20 亿条记录,我必须从该表中获取具有最大评论数的 post_id
:
select post_id,Count(id) as total from comments group by post_id
但这给了我所有现有的帖子 ID 及其来自上述查询的评论。我只想要评论数最多的帖子 ID
最佳答案
select post_id, Count(id) as total
from comments
group by post_id
order by total desc
limit 1
关于Mysql - 尝试从评论表中获取具有最大评论数的帖子ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24117663/