标签:style blog http io ar color 使用 sp for
select *,COUNT(*) over() ‘全班人数‘ from Student
select *,COUNT(*) over(partition by Ssex) ‘性别人数‘ from Student --over()中加入partition by Ssex表示 按Ssex字段分组 男女分别为4人。
select *,ROW_NUMBER() over(order by year(sage)) ‘rownumber行号‘, RANK() over(order by year(sage)) ‘rank有并列而且会出现断号‘, dense_rank() over (order by year(sage)) ‘dense_rank密集排名‘, NTILE(4) over(order by year(sage)) ‘分组排名‘ from Student
select *,ROW_NUMBER() over(partition by year(sage) order by year(sage)) ‘rownumber行号‘ , RANK() over( partition by year(sage) order by year(sage)) ‘rank有并列而且会出现断号‘ , dense_rank() over ( partition by year(sage) order by year(sage)) ‘dense_rank密集排名‘, NTILE(4) over(partition by year(sage) order by year(sage)) ‘分组排名‘from Student
指定从基本结果集中返回附加的行,这些行包含与出现在
TOP
n (PERCENT) 行最后的
ORDER
BY
列中的值相同的值。
select top 3 with ties * from Student order by year(sage) --只取前3行,如果最后第3行中sage的年份和后面的年份相同,则附加随后的行
标签:style blog http io ar color 使用 sp for
原文地址:http://www.cnblogs.com/yangjingqi/p/4130699.html