--> (让你望见影子的墙)生成测试数据,时间:2008-12-01
 
if not object_id('tb') is null
drop table tb
Go
Create table tb([id] int,[score] int,[ranking] int)
Insert tb
select 1,95,0 union all
select 2,93,0 union all
select 3,88,0 union all
select 4,93,0 union all
select 5,84,0 union all
select 6,84,0 union all
select 7,88,0
Go
Select * from tbselect id,score,ranking=(select count(*) from tb where score>t.score)+1
from tb t
order by score desc1 95 1
2 93 2
4 93 2
3 88 4
7 88 4
5 84 6
6 84 6

解决方案 »

  1.   

    给你个参考
    你看下你的那个id的name 和 score 的name
    select StudentsId As 学员编号,(Score*109+5) As 成绩,randking(int,1,1)
    from score where (Score)>84
    order by Score DESC
      

  2.   

    if not object_id('tb') is null
        drop table tb
    Go
    Create table tb([id] int,[score] int,[ranking] int)
    Insert tb
    select 1,95,0 union all
    select 2,93,0 union all
    select 3,88,0 union all
    select 4,93,0 union all
    select 5,84,0 union all
    select 6,84,0 union all
    select 7,88,0
    update t set ranking=(select count(*)+1 from tb where [score]>t.[score]) from tb t
    select * from tb order by [ranking]
    /*id          score       ranking     
    ----------- ----------- ----------- 
    1           95          1
    2           93          2
    4           93          2
    3           88          4
    7           88          4
    5           84          6
    6           84          6(影響 7 個資料列)*/
      

  3.   


    if not object_id('tb') is null
        drop table tb
    Go
    Create table tb([id] int,[score] int,[ranking] int)
    Insert tb
    select 1,95,0 union all
    select 2,93,0 union all
    select 3,88,0 union all
    select 4,93,0 union all
    select 5,84,0 union all
    select 6,84,0 union all
    select 7,88,0
    GO
    select id,score,ranking=RANK()over(order by score desc) from tb