add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE X
(id int, section int)
;
insert into X
select 1, 6 from dual
union all select 2, 6 from dual
union all select 3, 7 from dual
union all select 4, 7 from dual
union all select 5, 6 from dual;
5 rows affected
with u as
(select id, section,
case when section = lag(section) over(order by id) then 0 else 1 end as grp
from X),
v as
(select id,
section,
sum(grp) over(order by id) as section_nr
from u)
select section,
section_nr,
min(id) as first_id
from v
group by section, section_nr;
SECTION SECTION_NR FIRST_ID
6 3 5
7 2 3
6 1 1