【问题标题】:Mysql - Trying to get post id with max number of comments from comment tableMysql - 试图从评论表中获取具有最大评论数的帖子ID
【发布时间】: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


    【解决方案1】:
    select post_id, Count(id) as total 
    from comments 
    group by post_id
    order by total desc
    limit 1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-07
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 2020-01-09
      • 2020-05-06
      • 1970-01-01
      • 2016-01-02
      相关资源
      最近更新 更多