Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lab-sql-9.sql
Original file line number Diff line number Diff line change
@@ -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;