我有以下表博客(ID)和帖子(ID,blog_id,comment_count) 我需要从不同的博客中选择五个最多评论的职位。使用函数很容易,但是可以使用某种基本的SQL吗?帮助SQL查询
下面是在SQL Server方言
select top 5 top_post.* from Blogs b
cross apply
(select top 1 * from Posts p
where p.blog_id = b.id
order by p.comment_count) top_post
order by top_post.comment_count
实际上,您需要5个博客,并且我认为有顶级评论文章吗? – 2011-02-28 09:21:05