1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| WITH MaTable (num, id, typ, parentid, col, result)
AS
(
select 999, 10, 'ORIG', 10, 'ICP', 11 union all
select 999, 11, 'DUP' , 10, 'ICP', 12 union all
select 888, 12, 'ORIG', 12, 'ICP', 37 union all
select 888, 13, 'DUP' , 12, 'ICP', 39 union all
select 889, 14, 'ORIG', 14, 'ICP', 65 union all
select 890, 15, 'ORIG', 15, 'ICP', 73 union all
select 891, 16, 'ORIG', 16, 'ICP', 13 union all
select 892, 17, 'ORIG', 17, 'ICP', 19 union all
select 893, 18, 'ORIG', 18, 'ICP', 18 union all
select 894, 19, 'ORIG', 19, 'ICP', 31
)
select * from MaTable
where typ = 'DUP'
or id in (select parentid from MaTable
where typ = 'DUP');
num id typ parentid col result
----------- ----------- ---- ----------- ---- -----------
999 10 ORIG 10 ICP 11
999 11 DUP 10 ICP 12
888 12 ORIG 12 ICP 37
888 13 DUP 12 ICP 39 |
Partager