SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
select avg(days_between_rentals) avg_days_between_rentals from ( select tab.* ,case when return_date is null then 0 else datediff(next_rental_date, return_date) end days_between_rentals from ( select inventory_id ,rental_date ,return_date ,case when lead(rental_date) over(partition by inventory_id order by rental_date) is null then last_update else lead(rental_date) over(partition by inventory_id order by rental_date) end next_rental_date from rental ) tab ) t2

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear