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 rental_stats AS ( SELECT i.store_id, COUNT(*) AS total_rentals, SUM(CASE WHEN r.return_date IS NULL OR DATEDIFF(r.return_date, r.rental_date) > f.rental_duration THEN 1 ELSE 0 END) AS delayed_rentals FROM rental r JOIN inventory i ON r.inventory_id = i.inventory_id JOIN film f ON i.film_id = f.film_id GROUP BY i.store_id ) SELECT store_id, ROUND((delayed_rentals * 100.0 / NULLIF(total_rentals, 0)), 2) AS delayed_percent FROM rental_stats ORDER BY store_id; ; show status like 'Last_query_cost';

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

Copy Clear