Skip to content
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
Binary file added ERD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions gleek_code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
Original_Unnormalized_Table
int ID PK
string Title
string Director
string Director_country
string Star
Date Star_DOB
string writer
string Writer_email
int year
string Genre
int Score


Persons
int ID PK
string Name


DateOfBirths
int ID PK
Date dateOfBith
int PersonsID FK "unique"

HomeCountries
int ID PK
int PersonsID FK "unique"
int CountriesID FK

Countries
int ID PK
string name "unique"

Genres
int ID PK
string name "unique"

Emails
int ID PK
string Title
int PersonID FK "unique"

Movies
int ID PK
string Title
int Year
int score "range 0 to 10"
int DirectorID FK
int WriterID FK
int MovieStarID FK

Movie_Genre
int ID PK
int MoviesID FK
int GenresID FK


MovieStar
int ID PK
int PersonID FK

MovieDirector
int ID PK
int PersonID FK

MovieWriter
int ID PK
int PersonID FK

Cast
int ID PK
int MoviesID FK
int PersonID FK

Persons{1}--registered--{01}DateOfBirths
Persons{1}--registered--{01}HomeCountries
Countries{1}--registered--{0..n}HomeCountries

Movies{1}--registered--{1..n}Movie_Genre
Movie_Genre{1..n}--is--{1}Genres

Persons{1}--registrered--{01}Emails


MovieStar{1}--starIn--{1}Movies
MovieStar{01}--isA--{1}Persons

MovieDirector{1}--directed--{1}Movies
MovieDirector{01}--isA--{1}Persons

MovieWriter{1}--wrote--{1}Movies
MovieWriter{01}--isA--{1}Persons

Cast{0..n}--wrote--{1}Movies
Cast{0..n}--isA--{1}Persons
113 changes: 113 additions & 0 deletions planning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

# Use regex to get data from entries...


2001: A Space Odyssey
Stanley Kubrick
USA
Keir Dullea
30/05/1936
Arthur C Clarke
[email protected]
1968
Science Fiction
10

Star Wars: A New Hope
George Lucas
USA
Mark Hamill
25/09/1951
George Lucas
[email protected]
1977
Science Fiction
7

To Kill A Mockingbird
Robert Mulligan
USA
Gregory Peck
05/04/1916
Harper Lee
[email protected]
1962
Drama
10

Titanic
James Cameron
Canada
Leonardo DiCaprio
11/11/1974
James Cameron
[email protected]
1997
Romance
5

Dr Zhivago
David Lean
UK
Julie Christie
14/04/1940
Boris Pasternak
[email protected]
1965
Historical
8

El Cid
Anthony Mann
USA
Charlton Heston
04/10/1923
Frederick Frank
[email protected]
1961
Historical
6

Voyage to Cythera
Theodoros Angelopoulos
Greece
Manos Katrakis
14/08/1908
Theodoros Angelopoulos
[email protected]
1984
Drama
8

Soldier of Orange
Paul Verhoeven
Netherlands
Rutger Hauer
23/01/1944
Erik Hazelhoff Roelfzema
[email protected]
1977
Thriller
8

Three Colours: Blue
Krzysztof Kieslowski
Poland
Juliette Binoche
09/03/1964
Krzysztof Kieslowski
[email protected]
1993
Drama
8

Cyrano de Bergerac
Jean-Paul Rappeneau
France
Gerard Depardieu
27/12/1948
Edmond Rostand
[email protected]
1990
Historical
9
4 changes: 4 additions & 0 deletions queries/1_select.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Show the title and director name for all films


SELECT m.title, p.name FROM movies m INNER JOIN movie_director md ON md.id = m.director_id INNER JOIN persons p ON p.id = md.persons_id;
8 changes: 8 additions & 0 deletions queries/2_select.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Show the title, director and star name for all films

SELECT m.title, p.name AS Director, msp.name AS Star
FROM movies m
INNER JOIN movie_director md ON md.id = m.director_id
INNER JOIN movie_star ms ON ms.id = m.movie_star_id
INNER JOIN persons p ON p.id = md.persons_id
INNER JOIN persons msp ON msp.id = ms.persons_id;
11 changes: 11 additions & 0 deletions queries/3_select.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--Show the title of films where the director is from the USA

SELECT m.title, d.name AS Director, msp.name AS Star, c.countryname
FROM movies m
INNER JOIN movie_director md ON md.id = m.director_id
INNER JOIN movie_star ms ON ms.id = m.movie_star_id
INNER JOIN persons d ON d.id = md.persons_id
INNER JOIN persons msp ON msp.id = ms.persons_id
INNER JOIN home_countries homec ON homec.person_id = d.id
INNER JOIN countries c ON c.id= homec.countries_id
WHERE c.countryname LIKE '%USA%';
7 changes: 7 additions & 0 deletions queries/4_select.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--Show only those films where the writer and the director are the same person

SELECT m.title
FROM movies m
INNER JOIN movie_director md ON md.id = m.director_id
INNER JOIN movie_writer mw ON mw.id = m.movie_star_id
WHERE mw.persons_id = md.persons_id;
8 changes: 8 additions & 0 deletions queries/5_select.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--Show directors and film titles for films with a score of 8 or higher


SELECT m.title, p.name AS Director, m.score
FROM movies m
INNER JOIN movie_director md ON md.id = m.director_id
INNER JOIN persons p ON p.id = md.persons_id
WHERE m.score >= 8;
55 changes: 55 additions & 0 deletions queries/6_select.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--Make at least 5 more queries to demonstrate your understanding of joins, and other relationships between tables.


-- less than 8
SELECT m.title, p.name AS Director, m.score
FROM movies m
INNER JOIN movie_director md ON md.id = m.director_id
INNER JOIN persons p ON p.id = md.persons_id
WHERE m.score < 8;

-- All movies and genres
SELECT m.title, g.genre_name
FROM movies m
INNER JOIN genres_for_movies mg ON mg.movies_id = m.id
INNER JOIN genres g ON g.id = mg.genre_id;

-- All Drama Movies
SELECT m.title, g.genre_name
FROM movies m
INNER JOIN genres_for_movies mg ON mg.movies_id = m.id
INNER JOIN genres g ON g.id = mg.genre_id
where g.genre_name LIKE '%Drama%';


-- All Science Fiction by Cameron
SELECT m.title, g.genre_name
FROM movies m
INNER JOIN movie_director md ON md.id = m.director_id
INNER JOIN persons p ON md.persons_id = p.id
INNER JOIN genres_for_movies mg ON mg.movies_id = m.id
INNER JOIN genres g ON g.id = mg.genre_id
where g.genre_name LIKE '%Science Fiction%'
AND p.name LIKE '%James Cameron%'; -- results in 0 movies, because Aliens was not part of the list...

-- All Drama movies with a director from USA
SELECT m.title, g.genre_name
FROM movies m
INNER JOIN movie_director md ON md.id = m.director_id
INNER JOIN persons p ON md.persons_id = p.id
INNER JOIN home_countries hc ON hc.person_id = p.id
INNER JOIN countries c ON hc.countries_id = c.id
INNER JOIN genres_for_movies mg ON mg.movies_id = m.id
INNER JOIN genres g ON g.id = mg.genre_id
where g.genre_name LIKE '%Drama%'
AND c.countryname LIKE '%USA%';


-- select all other cast from the james cameraon movies
SELECT m.title, mc.persons_id, mcp.name
FROM movies m
INNER JOIN movie_director md ON md.id = m.director_id
INNER JOIN persons p ON md.persons_id = p.id
INNER JOIN cast_in_movies mc ON mc.movies_id = m.id
INNER JOIN persons mcp ON mcp.id = mc.persons_id
AND p.name LIKE '%James Cameron%';
Loading