select name,score,(select count(*) from t where score>a.score)+1
from t a
order by score

解决方案 »

  1.   

    两种形式
    上面是:1,2,3,3,3,6,7...
    下面是:1,2,3,3,3,4,5
    select name,score,(select count(distinct score) from t where score>a.score)+1
    from t a
    order by score
      

  2.   

    排序问题应该在前端处理,是界面显示的问题
    select * from yourtable order by 成绩
    如果非要,可以建立一个临时表,增加一个字段
    select *, IDENTITY(int, 1, 1) as id into #t2 from yourtable order by 成绩
    select * from #t2
      

  3.   

    select 成绩, IDENTITY(int, 1, 1) as id into #t2 from (select distinct 成绩  from a ) a order by a.成绩 desc
    select * from #t2 order by id 
      

  4.   

    select *,identity(int,1,1)as 排名 into #t from 表名 order by y desc
    select 姓名,成绩,排名=(select min(排名) from #t where 成绩=a.成绩 group by 成绩) from #t as a