From ff60aa7938ccbb71d54c428b6de653ba32cbff2a Mon Sep 17 00:00:00 2001 From: medilin Date: Sat, 16 Aug 2025 20:44:31 +0200 Subject: [PATCH 1/3] solved lab --- .gitignore | 2 ++ challenges.sql | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 .gitignore create mode 100644 challenges.sql diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f259787 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +sakila-data.sql +sakila-schema.sql diff --git a/challenges.sql b/challenges.sql new file mode 100644 index 0000000..ae7ef22 --- /dev/null +++ b/challenges.sql @@ -0,0 +1,60 @@ +USE sakila; + +SELECT + max(LENGTH) as max_duration, + min(LENGTH) as min_duration +FROM film; + +select + FLOOR(AVG(LENGTH)/60) as average_duration_hour, + FLOOR(AVG(LENGTH)%60) as average_duration_min +from FILM; + +select + DATEDIFF(max(rental_date), min(rental_date)) as days_of_operation +from rental; + +select *, + MONTHNAME(rental_date) as month_name, + DAYNAME(rental_date) as day_name, + CASE + WHEN WEEKDAY(rental_date) in (5, 6) THEN 'Weekend' + ELSE 'Workday' + END as day_type +from rental +limit 20; + +select + title, + IFNULL(rental_duration, 'Not available') as rental_duration +from film +ORDER BY title ASC; + +select + CONCAT(first_name,' ', last_name, ', ', SUBSTR(email, 1, 3)) +from customer +ORDER BY last_name ASC; + +-- The total number of films that have been released +select count(*) as total_films from film; + +-- The number of films for each rating, sorting the results in descending order of the number of films +select rating, count(*) from film +group by rating +order by count(*) desc; + +-- The mean film duration for each rating, and sort the results in descending order of the mean duration +select rating, ROUND(AVG(LENGTH), 2) as mean_film_duration from film +group by rating +order by AVG(LENGTH) desc; + +-- Identify which ratings have a mean duration of over two hours +select rating, ROUND(AVG(LENGTH), 2) as mean_film_duration from film +group by rating +HAVING AVG(LENGTH) >= 120 +order by AVG(LENGTH) desc; + +SELECT last_name, count(*) +FROM actor +GROUP BY last_name +HAVING COUNT(*) = 1; \ No newline at end of file From 49d6a6e5ee406f25566b8c9c7f6933f7c3d2459e Mon Sep 17 00:00:00 2001 From: medilin Date: Sat, 16 Aug 2025 20:53:24 +0200 Subject: [PATCH 2/3] split the first request --- challenges.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/challenges.sql b/challenges.sql index ae7ef22..f225de9 100644 --- a/challenges.sql +++ b/challenges.sql @@ -1,7 +1,10 @@ USE sakila; SELECT - max(LENGTH) as max_duration, + max(LENGTH) as max_duration +FROM film; + +SELECT min(LENGTH) as min_duration FROM film; From bfbd2c06f5e48459e929450f502b52e91469b5f9 Mon Sep 17 00:00:00 2001 From: medilin Date: Sat, 16 Aug 2025 21:07:16 +0200 Subject: [PATCH 3/3] combined the firtst request --- challenges.sql | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/challenges.sql b/challenges.sql index f225de9..778f07a 100644 --- a/challenges.sql +++ b/challenges.sql @@ -1,11 +1,7 @@ USE sakila; SELECT - max(LENGTH) as max_duration -FROM film; - -SELECT - min(LENGTH) as min_duration + max(LENGTH) as max_duration, min(LENGTH) as min_duration FROM film; select