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 film_rentals AS ( SELECT f.film_id, f.title, COUNT(r.rental_id) AS rental_count FROM film f JOIN inventory i ON f.film_id = i.film_id JOIN rental r ON i.inventory_id = r.inventory_id WHERE YEAR(r.rental_date) = 2005 GROUP BY f.film_id, f.title ), ranked_films AS ( SELECT title AS film_title, DENSE_RANK() OVER (ORDER BY rental_count DESC) AS film_rank FROM film_rentals ) SELECT film_rank, film_title FROM ranked_films WHERE film_rank <= 3 ORDER BY film_rank, film_title;

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

Copy Clear