with timeline as (
select rental_date dt
from rental
where customer_id = 1
)
, dts as (
select dt, r.rental_date, r.return_date
, coalesce(1+sum(case when rental_id is null then 1 end) over(order by dt),1) period_id
from timeline tm
left join rental r on r.customer_id = 1 and tm.dt >= r.rental_date and tm.dt < r.return_date
)
select * from dts;
select period_id
, min(rental_date) from_date, max(return_date) to_date
from dts
group by period_id
having count(*) > 1
order by 1
;