日期:2014-05-18 浏览次数:20581 次
--> 测试数据:[test] if object_id('[test]') is not null drop table [test] create table [test]([排名] int,[名字] varchar(2),[分数] int) insert [test] select 1,'aa',100 union all select 2,'bb',99 union all select 3,'cc',98 union all select 3,'dd',98 union all select 4,'ee',97 union all select 5,'ff',96 select * from( select [排名]=ROW_NUMBER()over(order by [分数] desc), [名字],[分数] from test )t where [排名]<=(select MAX([排名]) from test) /* 排名 名字 分数 1 aa 100 2 bb 99 3 cc 98 4 dd 98 5 ee 97 */
------解决方案--------------------
select [排名]=ROW_NUMBER()over(order by [分数] desc), [名字],[分数] from test
------解决方案--------------------
1.RANK() OVER()——重复,不连续,1,1,3
2.DENSE_RANK() OVER()——重复,连续,1,1,2
3.ROW_NUMBER() OVER()——不重复,连续,1,2,3