-
-
Save marcopeg/881bddd7f8449279cb9b4e8dbddfd6ee to your computer and use it in GitHub Desktop.
SQL Trainint with ChatGPT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO movies (title, release_year, revenue) | |
VALUES ('Avatar', 2009, 2787.97), | |
('Avengers: Endgame', 2019, 2797.8), | |
('Titanic', 1997, 2208.6), | |
('Star Wars: The Force Awakens', 2015, 2068.22), | |
('Avengers: Infinity War', 2018, 2048.06), | |
('Jurassic World', 2015, 1671.71), | |
('The Lion King', 2019, 1656.94), | |
('The Avengers', 2012, 1519), | |
('Furious 7', 2015, 1516.05), | |
('Frozen II', 2019, 1450.03); | |
INSERT INTO categories (name) | |
VALUES ('Action'), | |
('Romance'), | |
('Adventure'), | |
('Animation'); | |
INSERT INTO tags (name) | |
VALUES ('Sci-Fi'), | |
('Superheroes'), | |
('Epic'), | |
('Drama'); | |
INSERT INTO actors (name) | |
VALUES ('Tom Cruise'), | |
('Robert Downey Jr.'), | |
('Leonardo DiCaprio'), | |
('Chris Hemsworth'), | |
('Gal Gadot'); | |
INSERT INTO movie_categories (movie_id, category_id) | |
VALUES (1, 1), | |
(2, 1), | |
(3, 2), | |
(4, 1), | |
(5, 1), | |
(6, 3), | |
(7, 4), | |
(8, 1), | |
(9, 1), | |
(10, 4); | |
INSERT INTO movie_tags (movie_id, tag_id) | |
VALUES (1, 1), | |
(2, 2), | |
(2, 3), | |
(3, 4), | |
(4, 1), | |
(5, 2), | |
(5, 3), | |
(6, 1), | |
(7, 4), | |
(8, 2), | |
(9, 1), | |
(10, 3); | |
INSERT INTO movie_actors (movie_id, actor_id) | |
VALUES (1, 1), | |
(2, 2), | |
(3, 3), | |
(4, 2), | |
(5, 4), | |
(6, 1), | |
(6, 4), | |
(7, 3), | |
(8, 2), | |
(9, 1), | |
(10, 5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Give me the last 5 movies by revenue | |
SELECT title, revenue | |
FROM movies | |
ORDER BY revenue DESC | |
LIMIT 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE movies ( | |
id SERIAL PRIMARY KEY, | |
title TEXT, | |
release_year INTEGER, | |
revenue DECIMAL | |
); | |
CREATE TABLE categories ( | |
id SERIAL PRIMARY KEY, | |
name TEXT | |
); | |
CREATE TABLE tags ( | |
id SERIAL PRIMARY KEY, | |
name TEXT | |
); | |
CREATE TABLE actors ( | |
id SERIAL PRIMARY KEY, | |
name TEXT | |
); | |
CREATE TABLE movie_categories ( | |
movie_id INTEGER, | |
category_id INTEGER, | |
FOREIGN KEY (movie_id) REFERENCES movies (id), | |
FOREIGN KEY (category_id) REFERENCES categories (id), | |
PRIMARY KEY (movie_id, category_id) | |
); | |
CREATE TABLE movie_tags ( | |
movie_id INTEGER, | |
tag_id INTEGER, | |
FOREIGN KEY (movie_id) REFERENCES movies (id), | |
FOREIGN KEY (tag_id) REFERENCES tags (id), | |
PRIMARY KEY (movie_id, tag_id) | |
); | |
CREATE TABLE movie_actors ( | |
movie_id INTEGER, | |
actor_id INTEGER, | |
FOREIGN KEY (movie_id) REFERENCES movies (id), | |
FOREIGN KEY (actor_id) REFERENCES actors (id), | |
PRIMARY KEY (movie_id, actor_id) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment