Рабочий раствор
ВЫХОД № 1
with dtes as (
select customer_id, prd_grp_id, date_from as dte, 1 as inc
from t
union all
select customer_id, prd_grp_id, date_to + 1, -1 as inc
from t
),
grps as (
select customer_id, prd_grp_id, dte as date_from,
lead(dte) over (partition by customer_id, prd_grp_id order by dte) - 1 as date_to,
sum(sum(inc)) over (partition by customer_id, prd_grp_id order by dte) as n_prods
from dtes
group by customer_id, prd_grp_id, dte
)
select * from grps where n_prods>0;
ВЫХОД № 2
with dtes as (
select customer_id, date_from as dte, 1 as inc
from t
union all
select customer_id, date_to + 1, -1 as inc
from t
),
totals as (
select customer_id, dte as date_from,
lead(dte) over (partition by customer_id order by dte) - 1 as date_to,
sum(sum(inc)) over (partition by customer_id order by dte) as num_prods,
(select count(distinct t2.prd_grp_id)
from t t2
where dtes.customer_id = t2.customer_id and
dtes.dte between t2.date_from and t2.date_to
) as num_groups
from dtes
group by customer_id, dte )
select * from totals where num_groups>0 order by customer_id, date_from;
Скрипка здесь
Спасибо @ Гордон Линофф !