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 rental_date dt from rental where customer_id = 1 ) , dts as ( select 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 ;

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

Copy Clear