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 prevRet from rental where customer_id = 1 order by return_date, rental_date ) , t2 ( select *, sum(if(prevRet > rentaL_date,0,1)) over(order by return_date, rental_date) as p from t ) select p as period_id, min(rental_date) as from_date, max(return_date) as to_date from t2 group by p

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear