【发布时间】:2014-06-09 09:50:11
【问题描述】:
在 MySQL 数据库表 cmets 中有超过 20 亿条记录,我必须从该表中获取具有最大 cmets 数量的 post_id:
select post_id,Count(id) as total from comments group by post_id
但这给了我所有现有的帖子 ID,他们对上述查询没有评论。我只想要最大数量的 cmets 的帖子 ID
【问题讨论】:
标签: mysql
在 MySQL 数据库表 cmets 中有超过 20 亿条记录,我必须从该表中获取具有最大 cmets 数量的 post_id:
select post_id,Count(id) as total from comments group by post_id
但这给了我所有现有的帖子 ID,他们对上述查询没有评论。我只想要最大数量的 cmets 的帖子 ID
【问题讨论】:
标签: mysql
select post_id, Count(id) as total
from comments
group by post_id
order by total desc
limit 1
【讨论】: