From a16632b902fc239b66ced040845fc542415aaaa0 Mon Sep 17 00:00:00 2001 From: andy-casagrande <163665556+andy-casagrande@users.noreply.github.com> Date: Sat, 11 May 2024 15:39:36 +0100 Subject: [PATCH] Add files via upload --- Lab SQL 7.sql | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 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..5ff9017 --- /dev/null +++ b/Lab SQL 7.sql @@ -0,0 +1,34 @@ +-- 1. Create a table rentals_may to store the data from rental table with information for the month of May. +CREATE TEMPORARY TABLE SAKILA.MAY_RENTALS AS +SELECT * FROM SAKILA.RENTAL +WHERE MONTH(RENTAL_DATE) = 5; + +-- 2. Insert values in the table rentals_may using the table rental, filtering values only for the month of May. +INSERT INTO MAY_RENTALS +SELECT * FROM SAKILA.RENTAL +WHERE MONTH(RENTAL_DATE) = 5; + +SELECT * FROM SAKILA.MAY_RENTALS; + +-- 3. Create a table rentals_june to store the data from rental table with information for the month of June. +CREATE TEMPORARY TABLE SAKILA.JUNE_RENTALS AS +SELECT * FROM SAKILA.RENTAL +WHERE MONTH(RENTAL_DATE) = 6; + +-- 4. Insert values in the table rentals_june using the table rental, +-- filtering values only for the month of June. +INSERT INTO JUNE_RENTALS +SELECT * FROM SAKILA.RENTAL +WHERE MONTH(RENTAL_DATE) = 6; + +SELECT * FROM SAKILA.JUNE_RENTALS; + +-- 5. Check the number of rentals for each customer for May. +SELECT CUSTOMER_ID, COUNT(*) AS CUSTOMER_MAY_COUNT +FROM SAKILA.MAY_RENTALS +GROUP BY CUSTOMER_ID; + +-- 6. Check the number of rentals for each customer for June. +SELECT CUSTOMER_ID, COUNT(*) AS CUSTOMER_JUNE_COUNT +FROM SAKILA.JUNE_RENTALS +GROUP BY CUSTOMER_ID;