From 29b490682363bc23983d4c977b331279e0013fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Marqu=C3=A9s=20Cabedo?= Date: Wed, 29 Apr 2026 20:25:58 +0200 Subject: [PATCH 1/2] Solved lab --- subqueries_lab.sql | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 subqueries_lab.sql diff --git a/subqueries_lab.sql b/subqueries_lab.sql new file mode 100644 index 0000000..89410c9 --- /dev/null +++ b/subqueries_lab.sql @@ -0,0 +1,27 @@ +USE sakila; + +-- 1.Determine the number of copies of the film "Hunchback Impossible" +-- that exist in the inventory system. + +SELECT COUNT(inventory_id) AS total_films +FROM inventory +WHERE film_id IN (SELECT film_id FROM 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. + +SELECT title +FROM film +WHERE length > (SELECT AVG(length) FROM film); + +-- 3.Use a subquery to display all actors who appear in the film "Alone Trip". + +SELECT first_name AS name, last_name AS surname +FROM actor +WHERE actor_id IN + (SELECT actor_id + FROM film_actor + WHERE film_id = + (SELECT film_id + FROM film + WHERE title = 'Alone Trip')); From b46597f39f4971626a2c8ca18915fe1c469be19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Marqu=C3=A9s=20Cabedo?= Date: Fri, 8 May 2026 16:27:42 +0200 Subject: [PATCH 2/2] upload changes --- subqueries_lab.sql | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/subqueries_lab.sql b/subqueries_lab.sql index 89410c9..c8cd782 100644 --- a/subqueries_lab.sql +++ b/subqueries_lab.sql @@ -3,16 +3,17 @@ USE sakila; -- 1.Determine the number of copies of the film "Hunchback Impossible" -- that exist in the inventory system. -SELECT COUNT(inventory_id) AS total_films +SELECT COUNT(*) AS total_films FROM inventory -WHERE film_id IN (SELECT film_id FROM film WHERE title = 'Hunchback Impossible'); +WHERE film_id = (SELECT film_id FROM 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. -SELECT title +SELECT title, length FROM film -WHERE length > (SELECT AVG(length) FROM film); +WHERE length > (SELECT AVG(length) FROM film) +ORDER BY length DESC; -- 3.Use a subquery to display all actors who appear in the film "Alone Trip". @@ -25,3 +26,5 @@ WHERE actor_id IN (SELECT film_id FROM film WHERE title = 'Alone Trip')); + +