select name, score, 排名=(select count(1) from tb where score>=a.score) from tb a
declare @t table([name] char(10),score int)insert into @t select 'song',100 union all select 'ttt',55 union all select '333',67 union all select 'rrty',87 union all select 'yyy',90select [name],score,(select count(*)+1 from @t where score>a.score) as mingci from @t a
select *,1+(select count(*) from course b where score<a.score) as 排名 from course a order by score
select *,1+(select count(*) from course b where a.score<score) as 排名 from course a order by score desc
不对吧,应该是select *,1+(select count(*) from course b where a.score>score) as 排名 from course a order by score desc
score,
排名=(select count(1) from tb where score>=a.score)
from tb a
select 'ttt',55 union all
select '333',67 union all
select 'rrty',87 union all
select 'yyy',90select [name],score,(select count(*)+1 from @t where score>a.score) as mingci from @t a
from course a
order by score
from course a
order by score desc
from course a
order by score desc