取出点击量最高的文章100篇,每个作者不超过5篇,怎么写?
id 文章id
title 文章标题
tips 点击量
author 作者
谢谢
------解决方案--------------------
- SQL code
select * from (select * from (select *,row_number() over (partition by author order by tips) rank from tb) t where rank<=100) T having count(T.author)<=5
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
- SQL code
Select Top 100 * from Articles A Where Id in(select Top 5 id from Articles Where author = A.author Order by tips desc)Order By tips desc
------解决方案--------------------
我看到4楼,觉得改一个order就对,于是看到了6楼,非常好的利用了sql新特性,再下边就没看下去,抱歉,6楼的应该正确,row_number效率我试过100万记录飞快