diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json new file mode 100644 index 0000000..f8b4888 --- /dev/null +++ b/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": null +} \ No newline at end of file diff --git a/.vs/api-sql-intro/v17/.wsuo b/.vs/api-sql-intro/v17/.wsuo new file mode 100644 index 0000000..bb49f0f Binary files /dev/null and b/.vs/api-sql-intro/v17/.wsuo differ diff --git a/.vs/api-sql-intro/v17/DocumentLayout.backup.json b/.vs/api-sql-intro/v17/DocumentLayout.backup.json new file mode 100644 index 0000000..02fb825 --- /dev/null +++ b/.vs/api-sql-intro/v17/DocumentLayout.backup.json @@ -0,0 +1,70 @@ +{ + "Version": 1, + "WorkspaceRootPath": "C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\", + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\sql\\products\\films_exercise.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}", + "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:sql\\products\\films_exercise.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}" + }, + { + "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\sql\\products\\create-products.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}", + "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:sql\\products\\create-products.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}" + }, + { + "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\sql\\products\\create-products.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}|CodeFrame", + "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:sql\\products\\create-products.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}|CodeFrame" + }, + { + "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\sql\\products\\films_exercise.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}|CodeFrame", + "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:sql\\products\\films_exercise.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}|CodeFrame" + } + ], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": 3, + "Children": [ + { + "$type": "Bookmark", + "Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}" + }, + { + "$type": "Bookmark", + "Name": "ST:128:0:{1fc202d4-d401-403c-9834-5b218574bb67}" + }, + { + "$type": "Bookmark", + "Name": "ST:129:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}" + }, + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "films_exercise.sql ", + "DocumentMoniker": "C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\sql\\products\\films_exercise.sql", + "RelativeDocumentMoniker": "sql\\products\\films_exercise.sql", + "ToolTip": "films_exercise.sql ", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000826|", + "WhenOpened": "2025-01-21T13:38:09.676Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 1, + "Title": "create-products.sql ", + "DocumentMoniker": "C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\sql\\products\\create-products.sql", + "RelativeDocumentMoniker": "sql\\products\\create-products.sql", + "ToolTip": "create-products.sql ", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000826|", + "WhenOpened": "2025-01-21T13:38:05.037Z", + "EditorCaption": "" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/.vs/api-sql-intro/v17/DocumentLayout.json b/.vs/api-sql-intro/v17/DocumentLayout.json new file mode 100644 index 0000000..02fb825 --- /dev/null +++ b/.vs/api-sql-intro/v17/DocumentLayout.json @@ -0,0 +1,70 @@ +{ + "Version": 1, + "WorkspaceRootPath": "C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\", + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\sql\\products\\films_exercise.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}", + "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:sql\\products\\films_exercise.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}" + }, + { + "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\sql\\products\\create-products.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}", + "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:sql\\products\\create-products.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}" + }, + { + "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\sql\\products\\create-products.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}|CodeFrame", + "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:sql\\products\\create-products.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}|CodeFrame" + }, + { + "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\sql\\products\\films_exercise.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}|CodeFrame", + "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:sql\\products\\films_exercise.sql||{CC5D8DF0-88F4-4BB2-9DBB-B48CEE65C30A}|CodeFrame" + } + ], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": 3, + "Children": [ + { + "$type": "Bookmark", + "Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}" + }, + { + "$type": "Bookmark", + "Name": "ST:128:0:{1fc202d4-d401-403c-9834-5b218574bb67}" + }, + { + "$type": "Bookmark", + "Name": "ST:129:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}" + }, + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "films_exercise.sql ", + "DocumentMoniker": "C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\sql\\products\\films_exercise.sql", + "RelativeDocumentMoniker": "sql\\products\\films_exercise.sql", + "ToolTip": "films_exercise.sql ", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000826|", + "WhenOpened": "2025-01-21T13:38:09.676Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 1, + "Title": "create-products.sql ", + "DocumentMoniker": "C:\\Users\\KBluch\\Documents\\Exercises\\api-sql-intro\\sql\\products\\create-products.sql", + "RelativeDocumentMoniker": "sql\\products\\create-products.sql", + "ToolTip": "create-products.sql ", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000826|", + "WhenOpened": "2025-01-21T13:38:05.037Z", + "EditorCaption": "" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000..d927d3f Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/sql/products/films_exercise.sql b/sql/products/films_exercise.sql new file mode 100644 index 0000000..ed123c7 --- /dev/null +++ b/sql/products/films_exercise.sql @@ -0,0 +1,124 @@ + CREATE TABLE films ( + id SERIAL PRIMARY KEY, + title VARCHAR(255) UNIQUE, + genre VARCHAR(50) , + release_year INT , + score INT CHECK (score BETWEEN 0 AND 10) +); + + +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); + +SELECT * FROM films; + +SELECT * FROM films +ORDER BY score DESC; + +SELECT * FROM films +ORDER BY score; + +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 BETWEEN 1990 and 1999; + +SELECT * FROM films +WHERE genre = 'SciFi'; + +SELECT * FROM films +WHERE genre = 'SciFi' OR genre= 'Western'; + +SELECT * FROM films +WHERE genre NOT IN ('SciFi'); + +SELECT * FROM films +WHERE genre = 'Western' AND release_year < 2000; + +SELECT * FROM films +WHERE title LIKE '%Matrix%'; + + +CREATE TABLE films2 ( +id SERIAL PRIMARY KEY, +title VARCHAR(255) , +genre VARCHAR(50) , +release_year INT , +score INT CHECK (score BETWEEN 0 AND 10), +directorId INT, +FOREIGN KEY (directorId) REFERENCES directors2(id) +); + +CREATE TABLE directors2 ( + id SERIAL PRIMARY KEY, + name VARCHAR(50) +); + +INSERT INTO directors2 (name) +VALUES + ('Steven Spielberg'), + ('Martin Scorsese'), + ('Christopher Nolan'), + ('Alfred Hitchcock'), + ('Woody Allen'), + ('Kristoffer Blücher'); + + +INSERT INTO films2 (title, genre, release_year, 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, 5), + ('Total Recall', 'SciFi', 1990, 8, 2), + ('The Matrix', 'SciFi', 1999, 8, 3), + ('The Matrix Resurrections', 'SciFi', 2021, 5, 4), + ('The Matrix Reloaded', 'SciFi', 2003, 6, 5), + ('The Hunt for Red October', 'Thriller', 1990, 7, 6), + ('Misery', 'Thriller', 1990, 7, 5), + ('The Power Of The Dog', 'Western', 2021, 6, 1), + ('Hell or High Water', 'Western', 2016, 8, 1), + + + + +SELECT films2.title AS film_title, + films2.genre, + films2.release_year, + films2.score, + directors2.name AS director_name +FROM films2 +JOIN directors2 ON films2.directorId = directors2.id; + + +SELECT directors2.name, COUNT(films2.id) AS number_of_films +FROM directors2 +JOIN films2 ON directors2.id = films2.directorId +GROUP BY directors2.name; \ No newline at end of file