Created
April 26, 2025 06:45
-
-
Save ashen007/af8072201282eef02cf74e6ac8a542df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Question: which film has the most rentals? | |
| SQL Query: | |
| select title, | |
| count(rental_id) as rental_count | |
| from film | |
| join (select i.film_id, | |
| r.rental_id | |
| from inventory as i | |
| join rental as r on i.inventory_id = r.inventory_id) as t | |
| on film.film_id = t.film_id | |
| group by title | |
| order by rental_count desc; | |
| Question: which film has the most revenue? | |
| SQL Query: | |
| select title, | |
| sum(amount * rental_period) as revenue | |
| from film | |
| join (select i.film_id, | |
| r.* | |
| from inventory as i | |
| join (select rental.inventory_id, | |
| rental.rental_id, | |
| amount, | |
| datediff(return_date, rental_date) as rental_period | |
| from rental | |
| join payment on rental.rental_id = payment.rental_id) as r | |
| on i.inventory_id = r.inventory_id) as t | |
| on film.film_id = t.film_id | |
| group by title | |
| order by revenue desc | |
| limit 1; | |
| Question: which film has the highest rental period? | |
| SQL Query: | |
| select title, | |
| max(datediff(return_date, rental_date)) as rental_period | |
| from film | |
| join (select i.film_id, | |
| r.rental_id, | |
| rental_date, | |
| return_date | |
| from inventory as i | |
| join rental as r | |
| on i.inventory_id = r.inventory_id) as t | |
| on film.film_id = t.film_id | |
| group by title; | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment