取出点击量最高的文章100篇,每个作者不超过5篇

--取出点击量最高的文章100篇,每个作者不超过5篇
select top 100 id,title,tips,author 
from
select *,cnt=row_number() over (partition by author order by tips desc
from tb 
) t 
where cnt <=5 
order by tips desc 

 

 

 

 

--A B 连表 找出对应号码 最大id所对应的公司id
select top 1000 a.phone, b.* from  dbo.Send_Api a 
left join (
select   SendID , CompanyID , Phone ,  cnt = row_number() over (partition by phone order by SendID desc) from send
) b 
on case when len(a.phone)>11 then substring(a.Phone, 3, 11)  else a.Phone end=b.phone and b.cnt=1

 

 


posted @ 2010-01-03 10:50  曾祥展  阅读(1906)  评论(0编辑  收藏  举报