SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
with t as ( select rental_date, return_date, lag(return_date) over(order by return_date, rental_date) as prv from rental where customer_id = 1 order by return_date, rental_date ) select p + 1 as period_id, min(rental_date) as from_date, max(return_date) as to_date from (select rental_date, return_date, prv, sum(if(rental_date > prv, 1, 0)) over(order by return_date, rental_date) as p from t) as s group by period_id

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear