From e151590a293ed470954fa6b8c4e485f7fe18ba1f Mon Sep 17 00:00:00 2001 From: Padb95 Date: Sat, 11 May 2024 12:45:18 +0100 Subject: [PATCH] Done --- lab-sql-9.sql | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lab-sql-9.sql diff --git a/lab-sql-9.sql b/lab-sql-9.sql new file mode 100644 index 0000000..52dfe22 --- /dev/null +++ b/lab-sql-9.sql @@ -0,0 +1,33 @@ +-- Create a table rentals_may to store the data from rental table with information for the month of May. +CREATE TABLE RENTAL_MAY AS +SELECT * +FROM SAKILA.RENTAL +WHERE EXTRACT(MONTH FROM RENTAL_DATE) = 5; + +-- Insert values in the table rentals_may using the table rental, filtering values only for the month of May. +INSERT INTO RENTAL_MAY +SELECT * +FROM SAKILA.RENTAL +WHERE EXTRACT(MONTH FROM rental_date) = 5; + +-- Create a table rentals_june to store the data from rental table with information for the month of June. +CREATE TEMPORARY TABLE RENTAL_JUNE AS +SELECT * +FROM SAKILA.RENTAL +WHERE EXTRACT(MONTH FROM RENTAL_DATE) = 6; + +-- Insert values in the table rentals_june using the table rental, filtering values only for the month of June. +INSERT INTO RENTAL_JUNE +SELECT * +FROM SAKILA.RENTAL +WHERE EXTRACT(MONTH FROM RENTAL_DATE) = 6; + +-- Check the number of rentals for each customer for May. +SELECT CUSTOMER_ID, COUNT(*) AS MAY_COUNT +FROM SAKILA.RENTAL +GROUP BY 1; + +-- Check the number of rentals for each customer for June. +SELECT CUSTOMER_ID, COUNT(*) AS JUNE_COUNT +FROM SAKILA.RENTAL +GROUP BY 1;