Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
with timeline as ( select distinct case k when 1 then rental_date else return_date end dt from rental, (select 1 k union all select 2) t where customer_id = 1 ) , dts as ( select dt , 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 period_id , min(dt) from_date, max(dt) to_date from dts group by period_id order by 1 ;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear