Skip to content
Open
Show file tree
Hide file tree
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
File renamed without changes.
50 changes: 50 additions & 0 deletions sql/films/extension-2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
DROP TABLE IF EXISTS directors CASCADE;

CREATE TABLE directors
(
id serial PRIMARY KEY,
name VARCHAR(255)
);

DROP TABLE IF EXISTS films;

CREATE TABLE films (
id serial PRIMARY KEY,
title VARCHAR(255) NOT NULL,
genre VARCHAR(255),
release_year INT,
score INT,
director_id INT,
FOREIGN KEY (director_id) REFERENCES directors(id)
ON DELETE SET NULL,
UNIQUE(title)
);

INSERT INTO directors (name) VALUES
('Dir1'),
('Dir2'),
('Dir3'),
('Dir4'),
('Dir5'),
('Dir6');


INSERT INTO films (title, genre, release_year, score, director_id) VALUES
('The Shawshank Redemption', 'Drama', 1994, 9, 1),
('The Godfather', 'Crime', 1972, 9, 3),
('The Dark Knight', 'Action', 2008, 9, 5),
('Alien', 'SciFi', 1979, 9, 2),
('Total Recall', 'SciFi', 1990, 8, 4),
('The Matrix', 'SciFi', 1999, 8, 6),
('The Matrix Resurrections', 'SciFi', 2021, 5, 3),
('The Matrix Reloaded', 'SciFi', 2003, 6, 1),
('The Hunt for Red October', 'Thriller', 1990, 7, 5),
('Misery', 'Thriller', 1990, 7, 2),
('The Power Of The Dog', 'Western', 2021, 6, 6),
('Hell or High Water', 'Western', 2016, 8, 4),
('The Good the Bad and the Ugly', 'Western', 1966, 9, 1),
('Unforgiven', 'Western', 1992, 7, 3);

SELECT films.title, directors.name
FROM films
JOIN directors ON directors.id = films.director_id;
11 changes: 11 additions & 0 deletions sql/films/extension-3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SELECT directors.name, COUNT(films.id)
FROM directors
LEFT JOIN films ON directors.id = films.director_id
GROUP BY directors.name;







24 changes: 24 additions & 0 deletions sql/films/setup-films.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE TABLE films(
id serial PRIMARY KEY,
title VARCHAR(255) NOT NULL,
genre VARCHAR(255),
release_year INT,
score INT,
UNIQUE(title)
);

INSERT INTO films (title, genre, release_year, score) VALUES
('The Shawshank Redemption', 'Drama', 1994, 9),
('The Godfather', 'Crime', 1972, 9),
('The Dark Knight', 'Action', 2008, 9),
('Alien', 'SciFi', 1979, 9),
('Total Recall', 'SciFi', 1990, 8),
('The Matrix', 'SciFi', 1999, 8),
('The Matrix Resurrections', 'SciFi', 2021, 5),
('The Matrix Reloaded', 'SciFi', 2003, 6),
('The Hunt for Red October', 'Thriller', 1990, 7),
('Misery', 'Thriller', 1990, 7),
('The Power Of The Dog', 'Western', 2021, 6),
('Hell or High Water', 'Western', 2016, 8),
('The Good the Bad and the Ugly', 'Western', 1966, 9),
('Unforgiven', 'Western', 1992, 7);
8 changes: 0 additions & 8 deletions sql/products/create-products.sql

This file was deleted.