比如  table Acolumnname
8
10
100
3
10
希望用某个数句后输出
8,2
3,1
10,3
10,3
100,4或者
8,2
3,1
10,3
10,4
100,5

解决方案 »

  1.   


    --第一種
    Select 
    columnname,
    (Select Count(Distinct columnname) From A Where columnname <= T.columnname) As ID
    From
    A T
      

  2.   

    alter table A add  xx int identity(1,1)
    select columnname,xx from A
    这样也可以啊!
    嘿嘿!
      

  3.   

    select columnname, 
    (Select Count( columnname) From a
    Where columnname<= T.columnname)
     from a t
      

  4.   

    jadetiger(白玉老虎) ( ) 信誉:97    Blog   加为好友  2007-07-06 17:24:15  得分: 0  
     
     
       哈哈,有思路了,但是不对啊,如果出现了相等的,上面的方法算的排名就会跳空啊
      
     
    ------------
    我的不會啊。select columnname, 
    (Select Count( columnname) From a
    Where columnname<= T.columnname)
     from a t這個才會出現你說的情況
      

  5.   

    Create Table A
    (columnname Int)
    Insert A Select 8
    Union All Select 10
    Union All Select 100
    Union All Select 3
    Union All Select 10
    GO
    Select 
    columnname,
    (Select Count(Distinct columnname) From A Where columnname <= T.columnname) As ID
    From
    A T
    GO
    Drop Table A
    --Result
    /*
    columnname ID
    8 2
    10 3
    100 4
    3 1
    10 3
    */