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
5 changes: 5 additions & 0 deletions sql/extension1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT AVG(Score) from Films;

SELECT COUNT(*) FROM Films;

SELECT DISTINCT AVG(Score) as score, Genre FROM Films GROUP BY Genre ORDER BY score DESC ;
47 changes: 47 additions & 0 deletions sql/extension2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
DROP TABLE if exists directors;
drop table if exists Films;
CREATE TABLE directors(
directorID SERIAL not null ,
firstName varchar,
lastname VARCHAR,
PRIMARY KEY(directorID)
);
CREATE TABLE Films(
FilmID BIGSERIAL PRIMARY KEY ,
Title VARCHAR,
Genre VARCHAR,
releaseYear INT,
Score INT,
directorid int REFERENCES directors(directorID)
);


INSERT INTO directors(firstname, lastname)
VALUES
('bob' , 'the builder'),
('big joe bo ' , 'the boo man'),
('bobplatsky' , 'the random named'),
('King B.J' , 'the bald');



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

Select firstName, lastName, title from directors
INNER JOIN Films ON directors.directorID = Films.directorId
GROUP By firstName, lastName, title;
6 changes: 6 additions & 0 deletions sql/extension3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

select Count(*) total , firstName, lastName from (Select Count( *) total, firstName, lastName from directors
INNER JOIN Films ON directors.directorID = Films.directorId
GROUP By firstName, lastName, title)
GROUP BY firstName, lastName;

27 changes: 27 additions & 0 deletions sql/insert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
DROP TABLE Films; -- so that i can run all

CREATE TABLE Films(
FilmID BIGSERIAL PRIMARY KEY ,
Title VARCHAR,
Genre VARCHAR,
releaseYear INT,
Score INT
);
INSERT INTO Films (Title, Genre, releaseYear, 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.

4 changes: 0 additions & 4 deletions sql/products/insert-products.sql

This file was deleted.

28 changes: 28 additions & 0 deletions sql/select.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

SELECT * FROM Films;

SELECT * FROM Films ORDER BY Score DESC;

SELECT * FROM Films ORDER BY releaseYear ASC;

SELECT * FROM Films WHERE Score >= 8;

SELECT * FROM Films WHERE Score <=7;

SELECT * FROM Films WHERE releaseYear = 1990;

SELECT * FROM Films WHERE releaseYear >= 2000;

SELECT * FROM Films WHERE releaseYear > 1990;

SELECT * FROM Films WHERE releaseYear <= 1999 AND releaseYear >= 1990;

SELECT * FROM Films WHERE Genre = 'SciFi';

SELECT * FROM Films WHERE Genre = 'SciFi' OR Genre = 'Western';

SELECT * FROM Films WHERE Genre != 'SciFi';

SELECT * FROM Films WHERE Genre = 'Western' AND releaseYear<2000;

SELECT * FROM Films WHERE Title LIKE '%Matrix%';