Assignment: SQL Joins and Clauses Using Sakila Database
These questions are for the Sakila database & Tables inside this database.
Part 1: SQL Joins
1. Inner Join:
o Write a query to find the names of customers and the titles of films they have
rented. Use an INNER JOIN between the customer, rental, and inventory
tables.
2. Left Outer Join:
o Write a query to list all customers and their rental history, including customers who
have not rented any films. Use a LEFT JOIN between the customer and rental
tables.
3. Right Outer Join:
o Write a query to list all films and the customers who have rented them, including
films that have not been rented. Use a RIGHT JOIN between the film,
inventory, and rental tables.
Part 2: WHERE and ORDER BY Clauses
4. WHERE Clause:
o Write a query to find the details of rentals that were returned late. Use the rental
and inventory tables and filter by return_date.
o Write a query to find all customers who live in a specific city, e.g., "San Francisco".
Use the customer and address tables.
5. ORDER BY Clause:
o Write a query to list all films in the film table ordered by rental rate in descending
order.
o Write a query to list all customers ordered by their last names in ascending order.
Use the customer table.
Part 3: GROUP BY Clause
6. GROUP BY with Aggregate Functions:
o Write a query to find the total number of rentals for each film. Use GROUP BY on
the film_id and count the number of rentals.
o Write a query to find the number of rentals by each customer. Use GROUP BY on
the customer_id.
Part 4: Combined Concepts
7. Join and Group By:
o Write a query to find the total rental amount per customer for the last month. Use a
join between the customer, payment, and rental tables, and group by
customer_id.
o Write a query to find the average rental duration per film. Use the film and
rental tables, and group by film_id.
8. Advanced Filtering:
o Write a query to list the names of customers who have rented more than 5 different
films. Use the customer, rental, and inventory tables.
o Write a query to find the top 3 customers by total amount spent on rentals. Use the
customer and payment tables.