|
发表于 2020-5-21 13:30:01
|
显示全部楼层
declare @temptable table (
CW varchar(2) ,
Depth1 int,
Depth2 int
)
insert @temptable select 'A',2500,2512
union select 'B',2511,2513
union select 'A',2500,2512
union select 'A',2711,2080
union select 'A',2900,2901
union select 'B',1153,1787
select cw,Depth1,Depth2,ID = (select count(*) from @temptable b where a.depth1 >= b.depth1 and a.cw = b.cw group by cw) from @temptable a order by cw,Depth1
结果
/*
CW Depth1 Depth2 ID
A 2500 2512 1
A 2711 2080 2
A 2900 2901 3
B 1153 1787 1
B 2511 2513 2
*/
|
|