Skip to content
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

Abdi Mahamoud #263

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
done
  • Loading branch information
abdi0609 committed Jan 22, 2025
commit 38aa8fc6ef5f1b0082591e93a85706617b9d257e
60 changes: 60 additions & 0 deletions sql/products/core.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
CREATE TABLE films(
id serial PRIMARY KEY,
title VARCHAR(200) NOT NULL,
genre VARCHAR(200) NOT NULL,
release_year int NOT NULL,
score int NOT NULL,
directorid serial,
UNIQUE(title)
)

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


SELECT * FROM films

SELECT * FROM films AS f ORDER BY f.score DESC

SELECT * FROM films AS f ORDER BY f.release_year ASC

SELECT * FROM films AS f WHERE f.score >=8

SELECT * FROM films AS f WHERE f.score <=7

SELECT * FROM films AS f WHERE f.release_year = 1990

SELECT * FROM films AS f WHERE f.release_year < 2000

SELECT * FROM films AS f WHERE f.release_year > 1990

SELECT * FROM films AS f WHERE f.release_year > 1990 AND f.release_year < 2000

SELECT * FROM films AS f WHERE f.genre = 'SciFi'

SELECT * FROM films AS f WHERE f.genre = 'SciFi' OR f.genre = 'Western'

SELECT * FROM films AS f WHERE f.genre != 'SciFi'

SELECT * FROM films AS f WHERE f.genre = 'Western' AND f.release_year < 2000

SELECT * FROM films AS f WHERE f.title LIKE '%Matrix%'


SELECT AVG(films.score) FROM films

SELECT COUNT(films.title) FROM films

SELECT films.genre, AVG(films.score) AS average_score FROM films GROUP BY films.genre
23 changes: 23 additions & 0 deletions sql/products/extension.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SELECT AVG(films.score) FROM films

SELECT COUNT(films.title) FROM films

SELECT films.genre, AVG(films.score) AS average_score FROM films GROUP BY films.genre
CREATE TABLE directors (
id serial PRIMARY KEY,
name VARCHAR(200) NOT NULL,
film_count int NOT NULL
);

INSERT INTO directors (name,film_count) VALUES ('Christopher Nolan',10);
INSERT INTO directors (name,film_count) VALUES ('Steven Spielberg',3);
INSERT INTO directors (name,film_count) VALUES ('Quentin Tarantino',8);
INSERT INTO directors (name,film_count) VALUES ('Martin Scorsese',1);
INSERT INTO directors (name,film_count) VALUES ('Ridley Scott',45);

SELECT films.title, directors.name
FROM films
INNER JOIN directors ON films.directorid = directors.directorid;

SELECT directors.name, directors.film_count
FROM directors