34,873
社区成员
发帖
与我相关
我的任务
分享select [排名]=ROW_NUMBER()over(order by [分数] desc),
[名字],[分数] from test
--> 测试数据:[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
*/