Skip to content

'lab-sql-9' Pedro Barros #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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;