Вы можете использовать lead()
, чтобы получить пропущенные значения между строками, и union all
, чтобы ввести первое:
select serial_start + 1, next_ss - 1
from (select t.*,
lead(serial_start) over (partition by year order by serial_start) as next_ss
from t
where year = 2020
) t
where next_ss is not null or next_ss <> ss + 1
union all
select 1, min(serial_start) - 1
from t
where year = 2020
group by year
having min(serial_start) <> 1;