排名    名字    分数
1       aa 100
2 bb 99
3 cc 98
3  dd 98
4 ee 97
5 ff 96排名    名字    分数
1       aa 100
2 bb 99
3 cc 98
4  dd 98
5 ee 97

解决方案 »

  1.   


    --> 测试数据:[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',96select * 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
    */
      

  2.   

    select [排名]=ROW_NUMBER()over(order by [分数] desc),
    [名字],[分数] from test
      

  3.   

    1.RANK() OVER()——重复,不连续,1,1,3
    2.DENSE_RANK() OVER()——重复,连续,1,1,2
    3.ROW_NUMBER() OVER()——不重复,连续,1,2,3