diff --git a/joins_lab.sql b/joins_lab.sql new file mode 100644 index 0000000..83ff02a --- /dev/null +++ b/joins_lab.sql @@ -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; + + + + + +