table t 包含 
A int
B int
求个语句输入A,B,C,其中C为B在相同的A中的排序,比如1,3
1,6
2,2
2,1
1,5输出
1,3,1
1,6,3
2,2,2
2,1,1
1,5,2

解决方案 »

  1.   


    create table T(a int,b int)
    insert into T select 1,3
    insert into T select 1,6
    insert into T select 2,2
    insert into T select 2,1
    insert into T select 1,5
    select a,b,(select count(*) from T where a=TT.a and b<=TT.b)
    from T as TTdrop table T
      

  2.   

    create table T(a int,b int)
    insert into T select 1,3
    insert into T select 1,6
    insert into T select 2,2
    insert into T select 2,1
    insert into T select 1,5
    insert into T select 1,5
    select a,b,(select count(distinct b) from T where a=TT.a and b<=TT.b)
    from T as TTdrop table T
      

  3.   

    create table T(a int,b int)
    insert into T select 1,3
    insert into T select 1,6
    insert into T select 2,2
    insert into T select 2,1
    insert into T select 1,5
    insert into T select 1,5
    select a,b,(select count(distinct b) from T where a=TT.a and b<=TT.b) as c
    from T as TT
    order by a,b,cdrop table T
      

  4.   

    --加distinct即可select a,b,(select count(distinct b) from T where a=TT.a and b<=TT.b) as c
    from T as TT