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 26 27 28
| with t(col1, col2)
as (select 'AA', 'BB' from dual union all
select 'BB', 'CC' from dual union all
select 'CC', 'DD' from dual union all
select 'EE', 'FF' from dual union all
select 'GG', 'HH' from dual union all
select 'HH', 'ZZ' from dual
),
ruptures as (
select col1,
col2,
case when lag(col2, 1, 0) over (order by col1) <> col1 then 1 end flag_rupt
from t),
groupes as (
select col1,
col2,
flag_rupt,
sum(flag_rupt) over (order by col1) num_groupe
from ruptures)
select min(col1), max(col2)
from groupes
group by num_groupe;
MIN(COL1) MAX(COL2)
AA DD
EE FF
GG ZZ |
Partager