求个排序的语句
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
------解决方案--------------------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,c
drop table T
------解决方案----------------------加distinct即可
select a,b,(select count(distinct b) from T where a=TT.a and b <=TT.b) as c
from T as TT