From 2584e90cbb732e5071409b662607d9411a573026 Mon Sep 17 00:00:00 2001 From: Erlend Skutlaberg Date: Wed, 22 Jan 2025 13:49:31 +0100 Subject: [PATCH 1/2] Finished most of the tasks --- Extension 1.sql | 0 Extension 1.sql.tag | 0 Extension 2.sql | 0 Extension 2.sql.tag | 0 Extension 3.sql | 11 +++++++++ Extension 3.sql.tag | 0 Standard Criteria 2.sql | 49 +++++++++++++++++++++++++++++++++++++ Standard Criteria 2.sql.tag | 0 Standard Criteria.sql | 27 ++++++++++++++++++++ Standard Criteria.sql.tag | 0 10 files changed, 87 insertions(+) create mode 100644 Extension 1.sql create mode 100644 Extension 1.sql.tag create mode 100644 Extension 2.sql create mode 100644 Extension 2.sql.tag create mode 100644 Extension 3.sql create mode 100644 Extension 3.sql.tag create mode 100644 Standard Criteria 2.sql create mode 100644 Standard Criteria 2.sql.tag create mode 100644 Standard Criteria.sql create mode 100644 Standard Criteria.sql.tag diff --git a/Extension 1.sql b/Extension 1.sql new file mode 100644 index 0000000..e69de29 diff --git a/Extension 1.sql.tag b/Extension 1.sql.tag new file mode 100644 index 0000000..e69de29 diff --git a/Extension 2.sql b/Extension 2.sql new file mode 100644 index 0000000..e69de29 diff --git a/Extension 2.sql.tag b/Extension 2.sql.tag new file mode 100644 index 0000000..e69de29 diff --git a/Extension 3.sql b/Extension 3.sql new file mode 100644 index 0000000..1f7e981 --- /dev/null +++ b/Extension 3.sql @@ -0,0 +1,11 @@ +CREATE view directorNfilms1 AS +SELECT title, name from films_ext f +INNER JOIN directors d +ON f.directorId = d.id +GROUP BY d.name, f.title; + + +SELECT * FROM directorNfilms1; +SELECT ARRAY[CONCAT(name, CAST(COUNT(name) AS CHAR))] FROM directorNfilms1; + + diff --git a/Extension 3.sql.tag b/Extension 3.sql.tag new file mode 100644 index 0000000..e69de29 diff --git a/Standard Criteria 2.sql b/Standard Criteria 2.sql new file mode 100644 index 0000000..f46cd2f --- /dev/null +++ b/Standard Criteria 2.sql @@ -0,0 +1,49 @@ + +SELECT * FROM films; + + +SELECT * FROM films +ORDER BY (score) DESC; + + + +SELECT * FROM films +ORDER BY (release_year) DESC; + + +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) < 1999; + +SELECT * FROM films +WHERE (genre) = 'SciFi'; + +SELECT * FROM films +WHERE (genre) = 'SciFi' OR (genre) = 'Western'; + + +SELECT * FROM films +WHERE NOT (genre) = 'SciFi'; + +SELECT * FROM films +WHERE (genre) = 'Western' AND (release_year) < 2000; + +SELECT * FROM films +WHERE (title) LIKE '%Matrix%'; + + diff --git a/Standard Criteria 2.sql.tag b/Standard Criteria 2.sql.tag new file mode 100644 index 0000000..e69de29 diff --git a/Standard Criteria.sql b/Standard Criteria.sql new file mode 100644 index 0000000..dfe73c5 --- /dev/null +++ b/Standard Criteria.sql @@ -0,0 +1,27 @@ +CREATE TABLE films ( +id SERIAL, +title VARCHAR (50) UNIQUE, +genre VARCHAR(30), +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); + + diff --git a/Standard Criteria.sql.tag b/Standard Criteria.sql.tag new file mode 100644 index 0000000..e69de29 From 995e2d2687351531991f9739c8b4d337a5d2fe3d Mon Sep 17 00:00:00 2001 From: Erlend Skutlaberg Date: Wed, 22 Jan 2025 13:57:47 +0100 Subject: [PATCH 2/2] Finished all exercises --- Extension 3.sql | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Extension 3.sql b/Extension 3.sql index 1f7e981..5606ecd 100644 --- a/Extension 3.sql +++ b/Extension 3.sql @@ -1,11 +1,4 @@ -CREATE view directorNfilms1 AS -SELECT title, name from films_ext f +SELECT ARRAY[CONCAT(name, ':', CAST(COUNT(name) AS CHAR))] from films_ext f INNER JOIN directors d ON f.directorId = d.id -GROUP BY d.name, f.title; - - -SELECT * FROM directorNfilms1; -SELECT ARRAY[CONCAT(name, CAST(COUNT(name) AS CHAR))] FROM directorNfilms1; - - +GROUP BY d.name, f.title; \ No newline at end of file