|
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
result
/ *
CW Depth1 Depth2 ID
A 2500 2512 1
A 2711 2080 2
A 2900 2901 3
B 1153 1787 1
B 2511 2513 2
* / |
|