select *,(select count(*) from grades where score<= a.score) as [sort]
from grades a
order by score,name

解决方案 »

  1.   

    排反了select *,(select count(*) from grades where score>= a.score) as [sort]
    from grades a
    order by score desc ,name
      

  2.   

    select name,score sort form grades from grades order by score 
    alter  table  GRades  add   sort1  int  identity(1,1) //添加 
    sort1即是你想想的结果
      

  3.   

    select *,(select count(score)+1 from grades where score>a.score) as sort
    from grades a
    order by score desc
      

  4.   

    yat5460(现在就开始)没有两个第一啦.....
      

  5.   

    你是不是表里面根本就没有sort字段,想通过查询语句查出来?
      

  6.   

    create table #aa([name] varchar(10),score int ,sort int)
    insert into #aa
    select 'aa',99,1
    union all select 'bb',99,1
    union all select 'cc',90,1
    union all select 'dd',28,1
    union all select 'ee',59,1
    union all select 'ff',69,1declare @Mscore int,@mad int , @sort int,@score int ,@mid int
    set @mid=1
    set @mad=1
    set @Mscore=(select top 1 score  from #aa order by score desc)
    declare cur cursor for select score  from #aa order by score desc
    open cur
    fetch cur into @score 
    while @@fetch_status=0
    begin

    if @Mscore=@score
    begin 
    update #aa set sort=@mid where score=@score
    set @mad=@mad+1
    end
      else
    begin
    set @mid=@mad
    update #aa set sort=@mid where score=@score
    set @mad=@mad+1
    end
    set @Mscore=@score
    fetch cur into @score 

    end
    close cur
    deallocate cur
    select * from #aa order by sort这个可以.
      

  7.   

    to  aarondella() 
    似的,我想通过查询语句查出来。to  rea1gz(冒牌realgz V0.1) 
    不行,两个2,没有排名1的了。
      

  8.   

    select *,(select count(score)+1 from grades where score>a.score) as sort
                                 ^^                        ^^
                                加1                      去掉=号
    from grades a
    order by score desc这样就可以!
      

  9.   

    同意varysoft(), 是比较简单。
      

  10.   

    OK, varysof的方法可以解决我的问题了,谢谢各位朋友的帮助!