请问这条sql语句改怎么写?

某CMS中,文章表news和评论表comment字段如下:
      文章表news             评论表comment
      id文章id主键            ID评论id主键自增
      title文章标题            news_id关联文章表id
      content文章内容         status审核状态 0审核 1审核通过
      hits点击量         content评论内容
      created_time发布时间戳   created_time发布时间戳
      updated_time最后修改时间戳

1.文章排行榜页面需要展示一下数据
文章id 文章标题 点击量 评论量

要求按照当天的评论数量倒序排列 取前十名。
评论数相同则取较新的文章,没有评论则评论数量显示为0
用一条sql语句完成上述查询


Cats萌萌
浏览 570回答 1
1回答

慕田峪7331174

select a.*,t.c from news a inner join (select count(1) as c,news_id from comment group by news_id having count(1)>0 order by count(1) desc limit 10) t on a.id=t.news_id order by t.c desc,a.create_time desc;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL