我想取得排序的位置,比如:要作一个根据分数排名的。想知道每个人的都排在第几名。怎么取得所在的名次啊。大家给个例子啊。谢谢了

解决方案 »

  1.   

    create  table  #temp  (cj  decimal(10,2),pm  int)  
    go    
    insert  into  #temp(cj)  values(80)  
    insert  into  #temp(cj)  values(70)  
    insert  into  #temp(cj)  values(70)  
    insert  into  #temp(cj)  values(90)  
    insert  into  #temp(cj)  values(60)  
    insert  into  #temp(cj)  values(50)  
    go  
     
     
    update  #temp  set  pm=b.pm  from  #temp  a,(select  distinct  cj,(select  count(*)+1  from  #temp  where  cj>a.cj  )  as  pm  from  #temp  a  )  b  where  a.cj=b.cj  
     
     
    select  *  from  #temp  order  by  pm  
    drop  table  #temp  
     
    cj                      pm                      
    ------------  -----------    
    90.00                1  
    80.00                2  
    70.00                3  
    70.00                3  
    60.00                5  
    50.00                6  
     
    (所影响的行数为  6  行)
      

  2.   

    select mingci=1+(select count(*) from #t where zongfen>a.zongfen),a.* from #t a order by mingci