NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
[https://www.zhihu.com/question/327253526](https://www.zhihu.com/question/327253526) Top1 查文章列表分页并附带各自评论数点赞数最高的评论 ``` SELECT a.*,b.max_score from sc a INNER JOIN ( SELECT CId,max(score) max_score from sc GROUP BY CId ) b on a.CId= b.CId and a.score= b.max_score; ``` TopN 查文章列表分裂并附带各自评论数点赞数前5的评论 ``` select * from comment c where parent_id in ({ids}) and (select count(*) from comment s where c.parent_id = s.parent_id and c.created_at < s.created_at) < 5 ```