create table test (姓名 varchar(10), 分数 int ) insert test select 'aa' , 100 union all select 'bb' , 99 union all select 'cc' , 100 union all select 'dd' , 96 select * from test select 名次=(select count(*)+1 from test where 分数>a.分数),姓名,分数 from test a order by 名次
drop table test
姓名 分数 ---------- ----------- aa 100 bb 99 cc 100 dd 96(所影响的行数为 4 行)名次 姓名 分数 ----------- ---------- ----------- 1 aa 100 1 cc 100 3 bb 99 4 dd 96(所影响的行数为 4 行)
declare @t table(姓名 varchar(10),分数 int) insert into @t select 'aa' ,100 union all select 'bb' ,99 union all select 'cc' ,100 union all select 'dd' ,96select 名次=(select count(*)+1 from @t where 分数>a.分数),* from @t a order by 名次
(姓名 varchar(10),
分数 int
)
insert test
select 'aa' , 100 union all
select 'bb' , 99 union all
select 'cc' , 100 union all
select 'dd' , 96
select * from test
select 名次=(select count(*)+1 from test where 分数>a.分数),姓名,分数 from test a
order by 名次
drop table test
---------- -----------
aa 100
bb 99
cc 100
dd 96(所影响的行数为 4 行)名次 姓名 分数
----------- ---------- -----------
1 aa 100
1 cc 100
3 bb 99
4 dd 96(所影响的行数为 4 行)
insert into @t select 'aa' ,100
union all select 'bb' ,99
union all select 'cc' ,100
union all select 'dd' ,96select 名次=(select count(*)+1 from @t where 分数>a.分数),* from @t a order by 名次