-
Notifications
You must be signed in to change notification settings - Fork 0
/
movies.sql
104 lines (104 loc) Β· 2.13 KB
/
movies.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
-- Query 01
SELECT title
FROM movies
WHERE year = 2008;
-- Query 02
SELECT birth
FROM people
WHERE name = "Emma Stone";
-- Query 03
SELECT title
FROM movies
WHERE year >= 2018
ORDER BY title;
-- Query 04
SELECT COUNT(rating)
FROM ratings
WHERE rating = 10;
-- Query 05
SELECT title,
year
from movies
WHERE title LIKE "Harry Potter%"
ORDER BY year;
-- Query 06
SELECT AVG(rating)
FROM movies
JOIN ratings ON movies.id = ratings.movie_id
WHERE movies.year = 2012;
-- Query 07
SELECT movies.title,
ratings.rating
FROM movies
JOIN ratings ON movies.id = ratings.movie_id
WHERE movies.year = 2010
ORDER BY ratings.rating DESC,
movies.title;
-- Query 08
SELECT name
from movies,
stars,
people
WHERE title = "Toy Story"
AND movies.id = stars.movie_id
AND people.id = stars.person_id;
-- Query 09
SELECT name
FROM movies,
stars,
people
WHERE movies.year = 2004
AND stars.movie_id = movies.id
AND people.id = stars.person_id
ORDER BY people.birth;
-- Query 10
SELECT DISTINCT name
FROM directors,
people,
ratings
WHERE ratings.rating >= 9
AND ratings.movie_id = directors.movie_id
AND directors.person_id = people.id;
-- Query 11
SELECT movies.title
FROM movies,
stars,
people,
ratings
WHERE people.name = "Chadwick Boseman"
AND people.id = stars.person_id
AND stars.movie_id = movies.id
AND movies.id = ratings.movie_id
ORDER BY ratings.rating DESC
LIMIT 5;
-- Query 12
SELECT title
FROM movies,
stars,
people
WHERE people.name = "Johnny Depp"
AND movies.id = stars.movie_id
AND stars.person_id = people.id
AND title In (
SELECT title
FROM movies,
stars,
people
WHERE people.name = "Helena Bonham Carter"
AND movies.id = stars.movie_id
AND stars.person_id = people.id
);
-- Query 13
SELECT DISTINCT name
FROM stars,
people
WHERE stars.person_id = people.id
AND movie_id IN (
SELECT movie_id
FROM stars,
people
WHERE name = "Kevin Bacon"
AND stars.person_id = people.id
AND people.birth = 1958
)
AND name != "Kevin Bacon";