SQL 分类条件统计

来源:互联网 发布:冒泡排序法c语言 编辑:程序博客网 时间:2024/05/17 01:00
select T.* from (
select KURL ,
Sortup=sum (case when (InitialPage>CurrentPage or 
(InitialPage = CurrentPage and InitialRank > CurrentRank)) then 1 else 0 end),
Sortdown=sum (case when (InitialPage<CurrentPage or 
(InitialPage = CurrentPage and InitialRank < CurrentRank)) then 1 else 0 end),
Thesame=sum(case when(InitialPage = CurrentPage and InitialRank=CurrentRank) then 1 else 0 end),
firstpage=sum(case when(CurrentPage=1) then 1 else 0 end),row_number() over(order by KURL asc) as RowNum 
from  Keywords
group by KURL)T
where RowNum between {0} and {1}
0 0
原创粉丝点击