diff --git a/CREATE TABLE and INSERT.txt b/CREATE TABLE and INSERT.txt new file mode 100644 index 0000000..7bc912d --- /dev/null +++ b/CREATE TABLE and INSERT.txt @@ -0,0 +1,25 @@ +CREATE TABLE films ( +id SERIAL NOT NULL, +title VARCHAR(120) UNIQUE NOT NULL, +genre VARCHAR(40), +release_year INT, +score INT, +PRIMARY KEY (id) +); + +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); \ No newline at end of file diff --git a/Exercise - SELECT queries.txt b/Exercise - SELECT queries.txt new file mode 100644 index 0000000..60de687 --- /dev/null +++ b/Exercise - SELECT queries.txt @@ -0,0 +1,59 @@ +SELECT * +FROM films; + +SELECT * +FROM films +ORDER BY +score DESC; + +SELECT * +FROM films +ORDER BY +release_year ASC; + +SELECT * +FROM films +WHERE score >= 8; + +SELECT * +FROM films +WHERE score <= 7; + +SELECT * +FROM films +WHERE release_year = 1990; + +SELECT * +FROM films +WHERE release_year < 2000; + +SELECT * +FROM films +WHERE release_year > 1990; + +SELECT * +FROM films +WHERE release_year > 1990 +AND release_year < 2000; + +SELECT * +FROM films +WHERE genre = 'SciFi'; + +SELECT * +FROM films +WHERE genre = 'Western' +OR genre = 'SciFi'; + +SELECT * +FROM films +WHERE genre != 'SciFi'; + +SELECT * +FROM films +WHERE genre = 'Western' +AND release_year < 2000; + +SELECT * +FROM films +WHERE title LIKE '%Matrix%'; \ No newline at end of file diff --git a/Extension 1.txt b/Extension 1.txt new file mode 100644 index 0000000..888334c --- /dev/null +++ b/Extension 1.txt @@ -0,0 +1,9 @@ +SELECT AVG(score) +FROM films; + +SELECT COUNT(id) +FROM films; + +SELECT genre, AVG(score) +FROM films +GROUP BY genre; \ No newline at end of file diff --git a/Extension 2.txt b/Extension 2.txt new file mode 100644 index 0000000..5f64724 --- /dev/null +++ b/Extension 2.txt @@ -0,0 +1,48 @@ +CREATE TABLE directors ( +id SERIAL NOT NULL, +name VARCHAR(120), +PRIMARY KEY (id) +); + +CREATE TABLE films ( +id SERIAL NOT NULL, +title VARCHAR(120) UNIQUE NOT NULL, +genre VARCHAR(40), +release_year INT, +score INT, +director_id SERIAL, +PRIMARY KEY (id), +FOREIGN KEY(director_id) REFERENCES directors(id) +); + +INSERT INTO directors(name) +VALUES +('Johnny John Johnson'), +('Luke Star-Man'), +('Christopher Nolan'), +('Willy Western'), +('Sergio Leone'); + +INSERT INTO films (title, genre, release_year, score, director_id) +VALUES +('The Shawshank Redemption', 'Drama', 1994, 9, 3), +('The Godfather', 'Crime', 1972, 9, 3), +('The Dark Knight', 'Action', 2008, 9, 3), +('Alien', 'SciFi', 1979, 9, 1), +('Total Recall', 'SciFi', 1990, 8, 2), +('The Matrix', 'SciFi', 1999, 8, 2), +('The Matrix Resurrections', 'SciFi', 2021, 5, 2), +('The Matrix Reloaded', 'SciFi', 2003, 6, 1), +('The Hunt for Red October', 'Thriller', 1990, 7, 1), +('Misery', 'Thriller', 1990, 7, 3), +('The Power Of The Dog', 'Western', 2021, 6, 5), +('Hell or High Water', 'Western', 2016, 8, 5), +('The Good the Bad and the Ugly', 'Western', 1966, 9, 4), +('Unforgiven', 'Western', 1992, 7, 5); + + + +SELECT title, directors.name +FROM films +JOIN directors +ON films.director_id = directors.id; \ No newline at end of file diff --git a/Extension 3.txt b/Extension 3.txt new file mode 100644 index 0000000..91a40c5 --- /dev/null +++ b/Extension 3.txt @@ -0,0 +1,6 @@ +SELECT directors.name, COUNT(films) +FROM films +INNER JOIN directors +ON films.director_id = directors.id +GROUP BY directors.id +ORDER BY COUNT(films) DESC; \ No newline at end of file