From b5bc8f7c3144590247a680f7096af4cca83afb3c Mon Sep 17 00:00:00 2001 From: angelica Date: Thu, 6 Aug 2026 17:19:17 +0200 Subject: [PATCH 1/7] Lab Solved --- joins_lab.sql | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 joins_lab.sql diff --git a/joins_lab.sql b/joins_lab.sql new file mode 100644 index 0000000..dbae3bf --- /dev/null +++ b/joins_lab.sql @@ -0,0 +1,32 @@ +USE sakila; + +-- 1.List the number of films per category. +SELECT * FROM film_category as c +LEFT JOIN sakila.film AS f +ON c.film_id = f.film_id +ORDER BY c.category_id ASC; + +-- 2. Retrieve the store ID, city, and country for each store. +SELECT s.store_id, a.address_id, c.city_id, c.country_id FROM sakila.store AS s +JOIN sakila.city AS c +ON c.city_id = c.country_id +JOIN sakila.address AS a +ON s.address_id = a.address_id +ORDER BY s.store_id; + +-- 3. Calculate the total revenue generated by each store in dollars. +-- Where is the info? tables: payment, staff, stores +SELECT * FROM sakila.payment; + +SELECT s.store_id, SUM(p.amount) as 'Total Revenue' FROM sakila.payment AS p +JOIN sakila.staff AS f +ON p.staff_id = f.staff_id +JOIN sakila.store AS s +ON f.store_id = s.store_id +GROUP BY s.store_id; + + + + + + From 638f356508c3e084ad3a1af195c4e0cf2dd90d16 Mon Sep 17 00:00:00 2001 From: angelica Date: Thu, 6 Aug 2026 20:30:11 +0200 Subject: [PATCH 2/7] Joins sql Improved --- joins_lab.sql | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/joins_lab.sql b/joins_lab.sql index dbae3bf..4d6d5a0 100644 --- a/joins_lab.sql +++ b/joins_lab.sql @@ -1,28 +1,34 @@ USE sakila; -- 1.List the number of films per category. -SELECT * FROM film_category as c -LEFT JOIN sakila.film AS f +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 -ORDER BY c.category_id ASC; +GROUP BY ca.category_id; + +SELECT * FROM sakila.category; +SELECT * FROM sakila.film_category; + -- 2. Retrieve the store ID, city, and country for each store. -SELECT s.store_id, a.address_id, c.city_id, c.country_id FROM sakila.store AS s -JOIN sakila.city AS c -ON c.city_id = c.country_id +SELECT s.store_id, c.city, co.country FROM sakila.store AS s JOIN sakila.address AS a -ON s.address_id = a.address_id -ORDER BY s.store_id; +ON a.address_id = s.address_id +JOIN sakila.city AS c +ON c.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. -- Where is the info? tables: payment, staff, stores -SELECT * FROM sakila.payment; -SELECT s.store_id, SUM(p.amount) as 'Total Revenue' FROM sakila.payment AS p -JOIN sakila.staff AS f -ON p.staff_id = f.staff_id +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 f.store_id = s.store_id +ON ft.store_id = s.store_id GROUP BY s.store_id; From 6c77ed90af48cb1c80812c1b05a41cf50e3889b4 Mon Sep 17 00:00:00 2001 From: angelica Date: Thu, 6 Aug 2026 20:37:27 +0200 Subject: [PATCH 3/7] Lab Solved improved --- joins_lab.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/joins_lab.sql b/joins_lab.sql index 4d6d5a0..ea8f725 100644 --- a/joins_lab.sql +++ b/joins_lab.sql @@ -17,7 +17,7 @@ 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 c.city_id = c.city_id +ON a.city_id = c.city_id JOIN sakila.country AS co ON c.country_id = co.country_id; From 4722413cac213afabde44786e2aef0cf944175f7 Mon Sep 17 00:00:00 2001 From: angelica Date: Thu, 6 Aug 2026 21:44:04 +0200 Subject: [PATCH 4/7] subqueries solved --- subqueries_lab.sql | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 subqueries_lab.sql diff --git a/subqueries_lab.sql b/subqueries_lab.sql new file mode 100644 index 0000000..2cc922f --- /dev/null +++ b/subqueries_lab.sql @@ -0,0 +1,44 @@ + +USE sakila; + +-- 1.Determine the number of copies of the film "Hunchback Impossible" that exist in the inventory system. + +-- SELECT title FROM sakila.film; + +-- SELECT film_id FROM sakila.film +-- WHERE title = 'Hunchback Impossible'; + +SELECT COUNT(film_id) FROM sakila.inventory +WHERE film_id IN (SELECT film_id FROM sakila.film +WHERE title = 'Hunchback Impossible'); + +-- 2. List all films whose length is longer than the average length of all the films in the Sakila database. +-- Tables needed +SELECT ROUND(AVG(length)) AS Average FROM sakila.film; + +SELECT title, length FROM sakila.film +WHERE length > (SELECT ROUND(AVG(length)) FROM sakila.film) +ORDER BY length ASC; + +-- 3. Use a subquery to display all actors who appear in the film "Alone Trip". +-- Tables needed actor, film_actor, film with KEYS: actor_id, film_id + +SELECT first_name, last_name FROM sakila.actor +WHERE actor_id IN ( +SELECT actor_id +FROM sakila.film_actor +WHERE film_id IN ( +SELECT film_id +FROM sakila.film WHERE title = 'Alone Trip')); + + + + + + + + + + + + From c6a45a2f9712ad373326bee08a7d1b9ba34ae5b2 Mon Sep 17 00:00:00 2001 From: angelica Date: Tue, 18 Aug 2026 17:40:27 +0200 Subject: [PATCH 5/7] Removed incorrect file --- subqueries_lab.sql | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 subqueries_lab.sql diff --git a/subqueries_lab.sql b/subqueries_lab.sql deleted file mode 100644 index 2cc922f..0000000 --- a/subqueries_lab.sql +++ /dev/null @@ -1,44 +0,0 @@ - -USE sakila; - --- 1.Determine the number of copies of the film "Hunchback Impossible" that exist in the inventory system. - --- SELECT title FROM sakila.film; - --- SELECT film_id FROM sakila.film --- WHERE title = 'Hunchback Impossible'; - -SELECT COUNT(film_id) FROM sakila.inventory -WHERE film_id IN (SELECT film_id FROM sakila.film -WHERE title = 'Hunchback Impossible'); - --- 2. List all films whose length is longer than the average length of all the films in the Sakila database. --- Tables needed -SELECT ROUND(AVG(length)) AS Average FROM sakila.film; - -SELECT title, length FROM sakila.film -WHERE length > (SELECT ROUND(AVG(length)) FROM sakila.film) -ORDER BY length ASC; - --- 3. Use a subquery to display all actors who appear in the film "Alone Trip". --- Tables needed actor, film_actor, film with KEYS: actor_id, film_id - -SELECT first_name, last_name FROM sakila.actor -WHERE actor_id IN ( -SELECT actor_id -FROM sakila.film_actor -WHERE film_id IN ( -SELECT film_id -FROM sakila.film WHERE title = 'Alone Trip')); - - - - - - - - - - - - From 3ac0edd154ffd1f14c39cbba3136881a7ffd0ee5 Mon Sep 17 00:00:00 2001 From: angelica Date: Wed, 9 Sep 2026 15:12:21 +0200 Subject: [PATCH 6/7] Lab Improved --- joins_lab.sql | 3 --- 1 file changed, 3 deletions(-) diff --git a/joins_lab.sql b/joins_lab.sql index ea8f725..5992d63 100644 --- a/joins_lab.sql +++ b/joins_lab.sql @@ -8,9 +8,6 @@ JOIN sakila.film AS f ON c.film_id = f.film_id GROUP BY ca.category_id; -SELECT * FROM sakila.category; -SELECT * FROM sakila.film_category; - -- 2. Retrieve the store ID, city, and country for each store. SELECT s.store_id, c.city, co.country FROM sakila.store AS s From d19fafb20aeb13de93303740e94a18b1fc82f3d8 Mon Sep 17 00:00:00 2001 From: angelica Date: Wed, 9 Sep 2026 15:28:18 +0200 Subject: [PATCH 7/7] Lab Improved 2 --- joins_lab.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/joins_lab.sql b/joins_lab.sql index 5992d63..83ff02a 100644 --- a/joins_lab.sql +++ b/joins_lab.sql @@ -19,7 +19,7 @@ JOIN sakila.country AS co ON c.country_id = co.country_id; -- 3. Calculate the total revenue generated by each store in dollars. --- Where is the info? tables: payment, staff, stores + SELECT s.store_id, SUM(p.amount) as Total_Revenue FROM sakila.payment AS p JOIN sakila.staff AS ft