Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions joins_lab.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
USE sakila;

-- 1.List the number of films per category.
SELECT ca.name as category_name, COUNT(f.film_id) FROM sakila.category AS ca
JOIN film_category as c
ON ca.category_id = c.category_id
JOIN sakila.film AS f
ON c.film_id = f.film_id
GROUP BY ca.category_id;


-- 2. Retrieve the store ID, city, and country for each store.
SELECT s.store_id, c.city, co.country FROM sakila.store AS s
JOIN sakila.address AS a
ON a.address_id = s.address_id
JOIN sakila.city AS c
ON a.city_id = c.city_id
JOIN sakila.country AS co
ON c.country_id = co.country_id;

-- 3. Calculate the total revenue generated by each store in dollars.


SELECT s.store_id, SUM(p.amount) as Total_Revenue FROM sakila.payment AS p
JOIN sakila.staff AS ft
ON p.staff_id = ft.staff_id
JOIN sakila.store AS s
ON ft.store_id = s.store_id
GROUP BY s.store_id;