SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
with t as ( select row_number() over(order by return_date, rental_date) as n, rental_date as start_date, return_date as end_date, lag(return_date) over(order by return_date, rental_date) as prew_rent from rental where customer_id = 1 ), t2 as ( select *, sum(case when start_Date > prew_rent then 1 else 0 end) over(order by n) as period_id from t ) select period_id + 1, min(start_date) as from_date, max(end_date) to_date from t2 group by period_id

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear