From 6e37952d8880f613bd87145ae89101209e74b89b Mon Sep 17 00:00:00 2001 From: Yilak Kebede Date: Wed, 24 Sep 2025 21:36:02 +0200 Subject: [PATCH 1/2] Add Lab SQL Aggregation and Transformation assignment --- lab-sql-aggregation-and-transformation.sql | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lab-sql-aggregation-and-transformation.sql diff --git a/lab-sql-aggregation-and-transformation.sql b/lab-sql-aggregation-and-transformation.sql new file mode 100644 index 0000000..eacf977 --- /dev/null +++ b/lab-sql-aggregation-and-transformation.sql @@ -0,0 +1,43 @@ +use sakila; +-- 1. how many distinct actors last name are there? +select count(actor_id) from actor; + +-- 2. how many different language where films orginally produced +select count(language_id) from language; + +-- 3 how many movies were released with pg-13 + +select count(*) as movies_pG13 from film where rating = "PG-13"; +-- 4 get the longest movies from 2006 +SELECT title, length FROM film WHERE release_year = 2006 ORDER BY length DESC LIMIT 10; + +-- 5 how many days has the company been operating? +-- option 1 ( my thought) + +select count(distinct rental_date) as days_operating from rental; +-- result i got around 15815 days + +-- option 2 ( what i discover from other source, but since we have not study curdate(), i am hesitant to use it, + +SELECT DATEDIFF(CURDATE(), MIN(rental_date)) AS operating_days FROM rental; + +-- answer i got 6948 days + +-- Add an additional column day_type with values 'weekend' and 'workday' depending on the rental day of the week. + +SELECT + rental_id, + rental_date, + DATE_FORMAT(rental_date, '%M') AS month, + DATE_FORMAT(rental_date, '%W') AS weekday, + IF(WEEKDAY(rental_date) IN (5, 6), 'weekend', 'workday') AS day_type +FROM + rental +LIMIT 20; + +-- 8 How many rentals were in the last month of activity? + +SELECT COUNT(*) AS rentals_last_month +FROM rental +WHERE rental_date >= (SELECT MAX(rental_date) - INTERVAL 1 MONTH FROM rental); + From 18d69bf170e01aa7d371c3eaf546366890f1b6c1 Mon Sep 17 00:00:00 2001 From: Yilak Kebede Date: Wed, 24 Sep 2025 23:41:32 +0200 Subject: [PATCH 2/2] Submit Lab SQL Aggregation and Transformation assignment