From 51b910c4c8d5dcba8667783021c30be393499f71 Mon Sep 17 00:00:00 2001 From: haissaoliveira Date: Fri, 17 May 2024 22:41:24 +0100 Subject: [PATCH] LAB DONE --- lab-sql-7.sql | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 lab-sql-7.sql diff --git a/lab-sql-7.sql b/lab-sql-7.sql new file mode 100644 index 0000000..27c1830 --- /dev/null +++ b/lab-sql-7.sql @@ -0,0 +1,47 @@ +-- Create a table rentals_may to store the data from rental table with information for the month of May. + +CREATE TEMPORARY TABLE SAKILA.RENTALS_MAY AS +SELECT * +FROM SAKILA.RENTAL; + +SELECT RENTAL_DATE, +CONVERT(RENTAL_DATE, date) AS DATE_CONVERTED, +DATE_FORMAT(CONVERT(RENTAL_DATE, DATE), '%Y-%M-%D') RENTAL_INFO, +CASE WHEN DATE_FORMAT(CONVERT(RENTAL_DATE, DATE), '%M') IN ('May') THEN 'INFO MAY' +ELSE 'Other Month' END AS new_column +FROM SAKILA.RENTALS_MAY; + + +-- Insert values in the table rentals_may using the table rental, filtering values only for the month of May. + +SELECT * +FROM SAKILA.RENTALS_MAY; + +-- Create a table rentals_june to store the data from rental table with information for the month of June. +CREATE TEMPORARY TABLE SAKILA.RENTALS_JUNE AS +SELECT * +FROM SAKILA.RENTAL; + +SELECT RENTAL_DATE, +CONVERT(RENTAL_DATE, date) AS DATE_CONVERTED, +DATE_FORMAT(CONVERT(RENTAL_DATE, DATE), '%Y-%M-%D') RENTAL_INFO, +CASE WHEN DATE_FORMAT(CONVERT(RENTAL_DATE, DATE), '%M') IN ('June') THEN 'RENTAL JUNE' +ELSE 'Other Month' END AS new_column +FROM SAKILA.RENTALS_JUNE +; + +-- Insert values in the table rentals_june using the table rental, filtering values only for the month of June. +SELECT * +FROM SAKILA.RENTALS_JUNE; + +-- Check the number of rentals for each customer for May. +SELECT CUSTOMER_ID, COUNT(RENTAL_ID) AS RENTAL_PER_CUSTOMER +FROM SAKILA.RENTALS_MAY +GROUP BY 1 +ORDER BY 2; + +-- -- Check the number of rentals for each customer for June. +SELECT CUSTOMER_ID, COUNT(RENTAL_ID) AS RENTAL_PER_CUSTOMER +FROM SAKILA.RENTALS_JUNE +GROUP BY 1 +ORDER BY 2;