From 5a9529643b6cece7ce28a99e326b500e283256b1 Mon Sep 17 00:00:00 2001 From: dianayule Date: Sat, 23 May 2026 15:02:18 +0200 Subject: [PATCH 1/6] LAb solvedv1 --- sakila_labsolution.sql | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 sakila_labsolution.sql diff --git a/sakila_labsolution.sql b/sakila_labsolution.sql new file mode 100644 index 0000000..513abaf --- /dev/null +++ b/sakila_labsolution.sql @@ -0,0 +1,69 @@ +USE sakila; + +-- 1. Displaying all tables in the Sakila database + +SHOW TABLES FROM sakila; + +-- Retrieve all the data from the tables actor, film and customer. +SELECT * FROM sakila.actor; +SELECT * FROM sakila.film; +SELECT * FROM sakila.film; + +-- 3.Retrieve he following columns from their respective tables: +-- 3.1 Titles of all films from the film table +SELECT title FROM sakila.film; +-- 3.2 List of languages used in films, with the column aliased as language from the language table +SELECT name as language FROM sakila.language; + +-- 3.3 List of first names of all employees from the staff table +SELECT first_name FROM sakila.staff; +-- Mike and Jon + +-- 4. Retrieve unique release years. +SELECT DISTINCT release_year FROM sakila.film; +-- only 2006 + +-- 5. Counting records for database insights: +-- 5.1 Determine the number of stores that the company has. +SELECT COUNT(store_id) AS Num_stores FROM sakila.store; +-- only 2 + +-- 5.2 Determine the number of employees that the company has. +SELECT COUNT(staff_id) AS Num_employees FROM sakila.staff; +-- only 2 + +-- 5.3 Determine how many films are available for rent and how many have been rented. +-- Number of files rented=183 +SELECT COUNT(inventory_id) +FROM sakila.rental +WHERE return_date IS NULL; + +-- Number of files available =15861 +SELECT COUNT(inventory_id) +FROM sakila.rental +WHERE return_date IS NOT NULL; + +-- 5.4 Determine the number of distinct last names of the actors in the database. +SELECT COUNT(DISTINCT last_name) FROM sakila.actor; +-- DISTINCT last names are 121 + +-- Retrieve the 10 longest films (lenght of 185) +SELECT title, length FROM sakila.film +ORDER BY length desc +LIMIT 10; + +-- 7. Use filtering techniques in order to: +-- 7.1 Retrieve all actors with the first name "SCARLETT". + +SELECT actor_id, first_name, last_name +FROM sakila.actor +WHERE first_name = 'SCARLETT'; + +-- 7.2 Retrieve all movies that have ARMAGEDDON in their title and have a duration longer than 100 minutes. +SELECT title, length FROM sakila.film +WHERE title LIKE '%ARMAGEDDON%' +AND length>100; + +-- 7.3 Determine the number of films that include Behind the Scenes content=538 +SELECT COUNT(special_features) FROM sakila.film +WHERE special_features LIKE '%Behind the Scenes%'; From f670159128a17868bf6d1cd6998a2fbc7b3ea098 Mon Sep 17 00:00:00 2001 From: dianayule Date: Sat, 23 May 2026 15:18:58 +0200 Subject: [PATCH 2/6] LAb solvedv2 --- sakila_labsolution.sql | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sakila_labsolution.sql b/sakila_labsolution.sql index 513abaf..6b3169c 100644 --- a/sakila_labsolution.sql +++ b/sakila_labsolution.sql @@ -7,7 +7,7 @@ SHOW TABLES FROM sakila; -- Retrieve all the data from the tables actor, film and customer. SELECT * FROM sakila.actor; SELECT * FROM sakila.film; -SELECT * FROM sakila.film; + -- 3.Retrieve he following columns from their respective tables: -- 3.1 Titles of all films from the film table @@ -17,7 +17,7 @@ SELECT name as language FROM sakila.language; -- 3.3 List of first names of all employees from the staff table SELECT first_name FROM sakila.staff; --- Mike and Jon + -- 4. Retrieve unique release years. SELECT DISTINCT release_year FROM sakila.film; @@ -33,16 +33,20 @@ SELECT COUNT(staff_id) AS Num_employees FROM sakila.staff; -- only 2 -- 5.3 Determine how many films are available for rent and how many have been rented. --- Number of files rented=183 +-- Number of files rented thus not available=183 SELECT COUNT(inventory_id) FROM sakila.rental WHERE return_date IS NULL; --- Number of files available =15861 -SELECT COUNT(inventory_id) +-- Number of files that have been rented, same film rented more than once counts as one file rented ever =4580 +SELECT COUNT(DISTINCT inventory_id) FROM sakila.rental WHERE return_date IS NOT NULL; +-- files registered in inventory = 4581 Thus files available are 4581-183= 4398 +SELECT COUNT(inventory_id) +FROM sakila.inventory; + -- 5.4 Determine the number of distinct last names of the actors in the database. SELECT COUNT(DISTINCT last_name) FROM sakila.actor; -- DISTINCT last names are 121 From 03a0b0a37491e7ec489d5a60f6cc317964b46735 Mon Sep 17 00:00:00 2001 From: dianayule Date: Sat, 23 May 2026 15:35:05 +0200 Subject: [PATCH 3/6] LAb solvedv3 --- sakila_labsolution.sql | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/sakila_labsolution.sql b/sakila_labsolution.sql index 6b3169c..d477082 100644 --- a/sakila_labsolution.sql +++ b/sakila_labsolution.sql @@ -7,6 +7,7 @@ SHOW TABLES FROM sakila; -- Retrieve all the data from the tables actor, film and customer. SELECT * FROM sakila.actor; SELECT * FROM sakila.film; +SELECT * FROM sakila.customer; -- 3.Retrieve he following columns from their respective tables: @@ -25,27 +26,21 @@ SELECT DISTINCT release_year FROM sakila.film; -- 5. Counting records for database insights: -- 5.1 Determine the number of stores that the company has. -SELECT COUNT(store_id) AS Num_stores FROM sakila.store; +SELECT COUNT(DISTINCT store_id) AS Num_stores FROM sakila.store; -- only 2 -- 5.2 Determine the number of employees that the company has. -SELECT COUNT(staff_id) AS Num_employees FROM sakila.staff; +SELECT COUNT(DISTINCT staff_id) AS Num_employees FROM sakila.staff; -- only 2 -- 5.3 Determine how many films are available for rent and how many have been rented. --- Number of files rented thus not available=183 -SELECT COUNT(inventory_id) -FROM sakila.rental -WHERE return_date IS NULL; +-- Number of fils available for rent 4580 +SELECT COUNT(DISTINCT inventory_id) +FROM sakila.rental; -- Number of files that have been rented, same film rented more than once counts as one file rented ever =4580 SELECT COUNT(DISTINCT inventory_id) -FROM sakila.rental -WHERE return_date IS NOT NULL; - --- files registered in inventory = 4581 Thus files available are 4581-183= 4398 -SELECT COUNT(inventory_id) -FROM sakila.inventory; +FROM sakila.rental; -- 5.4 Determine the number of distinct last names of the actors in the database. SELECT COUNT(DISTINCT last_name) FROM sakila.actor; From 17eca3bb26a0333dc3fd4c64fa3195c417e6aa2a Mon Sep 17 00:00:00 2001 From: dianayule Date: Sat, 23 May 2026 15:38:34 +0200 Subject: [PATCH 4/6] LAb solvedv4 --- sakila_labsolution.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sakila_labsolution.sql b/sakila_labsolution.sql index d477082..54951f0 100644 --- a/sakila_labsolution.sql +++ b/sakila_labsolution.sql @@ -27,26 +27,26 @@ SELECT DISTINCT release_year FROM sakila.film; -- 5. Counting records for database insights: -- 5.1 Determine the number of stores that the company has. SELECT COUNT(DISTINCT store_id) AS Num_stores FROM sakila.store; --- only 2 + -- 5.2 Determine the number of employees that the company has. SELECT COUNT(DISTINCT staff_id) AS Num_employees FROM sakila.staff; --- only 2 + -- 5.3 Determine how many films are available for rent and how many have been rented. --- Number of fils available for rent 4580 +-- 5.3 Number of films available for rent 4580 SELECT COUNT(DISTINCT inventory_id) FROM sakila.rental; --- Number of files that have been rented, same film rented more than once counts as one file rented ever =4580 +-- 5.3 Number of files that have been rented, same film rented more than once counts as one file rented ever =4580 SELECT COUNT(DISTINCT inventory_id) FROM sakila.rental; -- 5.4 Determine the number of distinct last names of the actors in the database. SELECT COUNT(DISTINCT last_name) FROM sakila.actor; --- DISTINCT last names are 121 --- Retrieve the 10 longest films (lenght of 185) + +-- 6. Retrieve the 10 longest films (lenght of 185) SELECT title, length FROM sakila.film ORDER BY length desc LIMIT 10; From 254302a452f14f7b484e1cc0435c9eacb280600a Mon Sep 17 00:00:00 2001 From: dianayule Date: Sat, 23 May 2026 15:54:02 +0200 Subject: [PATCH 5/6] LAb solvedv6 --- sakila_labsolution.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sakila_labsolution.sql b/sakila_labsolution.sql index 54951f0..3a8b4e2 100644 --- a/sakila_labsolution.sql +++ b/sakila_labsolution.sql @@ -34,12 +34,12 @@ SELECT COUNT(DISTINCT staff_id) AS Num_employees FROM sakila.staff; -- 5.3 Determine how many films are available for rent and how many have been rented. --- 5.3 Number of films available for rent 4580 +-- 5.3 Number of films available for rent SELECT COUNT(DISTINCT inventory_id) -FROM sakila.rental; +FROM sakila.inventory; --- 5.3 Number of files that have been rented, same film rented more than once counts as one file rented ever =4580 -SELECT COUNT(DISTINCT inventory_id) +-- 5.3 Number of files that have been rented +SELECT COUNT(rental_id) FROM sakila.rental; -- 5.4 Determine the number of distinct last names of the actors in the database. From 0b231b76ad47705bdff9c83619d34add21e4cec3 Mon Sep 17 00:00:00 2001 From: dianayule Date: Sat, 23 May 2026 15:58:13 +0200 Subject: [PATCH 6/6] LAb solvedv7 --- sakila_labsolution.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sakila_labsolution.sql b/sakila_labsolution.sql index 3a8b4e2..0a161ba 100644 --- a/sakila_labsolution.sql +++ b/sakila_labsolution.sql @@ -35,11 +35,11 @@ SELECT COUNT(DISTINCT staff_id) AS Num_employees FROM sakila.staff; -- 5.3 Determine how many films are available for rent and how many have been rented. -- 5.3 Number of films available for rent -SELECT COUNT(DISTINCT inventory_id) +SELECT COUNT(DISTINCT inventory_id) AS available_for_rent FROM sakila.inventory; -- 5.3 Number of files that have been rented -SELECT COUNT(rental_id) +SELECT COUNT(rental_id) AS rented FROM sakila.rental; -- 5.4 Determine the number of distinct last names of the actors in the database.