-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsql_queries.sql
More file actions
254 lines (227 loc) · 6.86 KB
/
Copy pathsql_queries.sql
File metadata and controls
254 lines (227 loc) · 6.86 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
use quest_bechdel;
# SCHEMA SETUP
# Setting constraints for bechdel_ratings table
ALTER TABLE bechdel_ratings
ADD PRIMARY KEY (bechdel_ID);
ALTER TABLE bechdel_ratings
ADD FOREIGN KEY (movie_info_ID) REFERENCES movie_info(movie_info_ID);
# Setting constraints for genres table
ALTER TABLE genres
MODIFY COLUMN genre_ID BIGINT;
ALTER TABLE genres
ADD PRIMARY KEY (genre_ID);
# Setting constraints for movie_genre table
ALTER TABLE movie_genre
ADD FOREIGN KEY (movie_info_ID) REFERENCES movie_info(movie_info_ID);
ALTER TABLE movie_genre
ADD FOREIGN KEY (genre_ID) REFERENCES genres(genre_ID);
# QUERIES RELATED TO RESEARCH QUESTION
# What genres are doing best/worst?
# Bechdel 0-3
SELECT gn.genre_name, AVG(br.bechdel_score) AS avg_b_score
FROM bechdel_ratings AS br
INNER JOIN movie_info AS mi
ON br.movie_info_ID = mi.movie_info_ID
INNER JOIN movie_genre AS mg
ON mi.movie_info_ID = mg.movie_info_ID
INNER JOIN genres AS gn
ON mg.genre_ID = gn.genre_ID
GROUP BY gn.genre_name
ORDER BY avg_b_score DESC;
# Bechdel fail/pass
SELECT gn.genre_name, AVG(br.bechdel_pass) AS percent_b_pass
FROM bechdel_ratings AS br
INNER JOIN movie_info AS mi
ON br.movie_info_ID = mi.movie_info_ID
INNER JOIN movie_genre AS mg
ON mi.movie_info_ID = mg.movie_info_ID
INNER JOIN genres AS gn
ON mg.genre_ID = gn.genre_ID
GROUP BY gn.genre_name
ORDER BY percent_b_pass DESC;
# Are indie movies doing better than “big” industry movies (cut off: budget 1 mio)?
# Bechdel 0-3
SELECT
CASE
WHEN budget < 1000000 THEN 'Indie film'
ELSE 'Major film'
END AS production_type,
AVG(bechdel_score) AS avg_b_score
FROM bechdel_ratings
INNER JOIN movie_info
USING(movie_info_ID)
GROUP BY production_type;
# Bechdel fail/pass
SELECT
CASE
WHEN budget < 1000000 THEN 'Indie film'
ELSE 'Major film'
END AS production_type,
AVG(bechdel_pass) AS percent_b_pass
FROM bechdel_ratings
INNER JOIN movie_info
USING(movie_info_ID)
GROUP BY production_type;
# Is the score related to the success of a movie?
# Revenue
# Bechdel 0-3
SELECT bechdel_score, AVG(revenue) AS avg_revenue
FROM bechdel_ratings
INNER JOIN movie_info
USING(movie_info_ID)
GROUP BY bechdel_score
ORDER BY bechdel_score ASC;
# (Setting up an additional export table for a scatterplot)
SELECT bechdel_score, revenue
FROM bechdel_ratings
INNER JOIN movie_info
USING(movie_info_ID)
ORDER BY bechdel_score;
# Bechdel fail/pass
SELECT bechdel_pass, AVG(revenue) AS avg_revenue
FROM bechdel_ratings
INNER JOIN movie_info
USING(movie_info_ID)
GROUP BY bechdel_pass
ORDER BY bechdel_pass ASC;
# IMDB rating
# Bechdel 0-3
SELECT bechdel_score, AVG(imdb_score/10) AS avg_imdb_score
FROM bechdel_ratings
INNER JOIN movie_info
USING(movie_info_ID)
GROUP BY bechdel_score
ORDER BY bechdel_score ASC;
# (Setting up an additional export table for a scatterplot)
SELECT bechdel_score, imdb_score/10
FROM bechdel_ratings
INNER JOIN movie_info
USING(movie_info_ID)
ORDER BY bechdel_score ASC;
# Bechdel fail/pass
SELECT bechdel_pass, AVG(imdb_score/10) AS avg_imdb_score
FROM bechdel_ratings
INNER JOIN movie_info
USING(movie_info_ID)
GROUP BY bechdel_pass
ORDER BY bechdel_pass ASC;
# Are movies doing better now than earlier (progression over years)?
# Bechdel 0-3
# All years
SELECT mi.year, AVG(br.bechdel_score) AS avg_b_score
FROM bechdel_ratings AS br
INNER JOIN movie_info AS mi
ON br.movie_info_ID = mi.movie_info_ID
GROUP BY mi.year
ORDER BY mi.year ASC;
# (Setting up an additional export table for a scatterplot)
SELECT mi.year, br.bechdel_score
FROM bechdel_ratings AS br
INNER JOIN movie_info AS mi
ON br.movie_info_ID = mi.movie_info_ID
ORDER BY mi.year ASC;
# Last ten years
SELECT mi.year, AVG(br.bechdel_score) AS avg_b_score
FROM bechdel_ratings AS br
INNER JOIN movie_info AS mi
ON br.movie_info_ID = mi.movie_info_ID
WHERE mi.year >= 2014
GROUP BY mi.year
ORDER BY mi.year ASC;
# Over the centuries
SELECT
CASE
WHEN movie_info.year < 1930 THEN '1920s'
WHEN movie_info.year BETWEEN 1930 AND 1939 THEN '1930s'
WHEN movie_info.year BETWEEN 1940 AND 1949 THEN '1940s'
WHEN movie_info.year BETWEEN 1950 AND 1959 THEN '1950s'
WHEN movie_info.year BETWEEN 1960 AND 1969 THEN '1960s'
WHEN movie_info.year BETWEEN 1970 AND 1979 THEN '1970s'
WHEN movie_info.year BETWEEN 1980 AND 1989 THEN '1980s'
WHEN movie_info.year BETWEEN 1990 AND 1999 THEN '1990s'
WHEN movie_info.year BETWEEN 2000 AND 2009 THEN '2000s'
WHEN movie_info.year BETWEEN 2010 AND 2019 THEN '2010s'
ELSE '2020s'
END AS century,
AVG(bechdel_score) AS avg_b_score
FROM bechdel_ratings
INNER JOIN movie_info
ON bechdel_ratings.movie_info_ID = movie_info.movie_info_ID
GROUP BY century
ORDER BY century ASC;
# Bechdel fail/pass
# All years
SELECT mi.year, AVG(br.bechdel_pass) AS percent_b_pass
FROM bechdel_ratings AS br
INNER JOIN movie_info AS mi
ON br.movie_info_ID = mi.movie_info_ID
GROUP BY mi.year
ORDER BY mi.year ASC;
# Last ten years
SELECT mi.year, AVG(br.bechdel_pass) AS percent_b_pass
FROM bechdel_ratings AS br
INNER JOIN movie_info AS mi
ON br.movie_info_ID = mi.movie_info_ID
WHERE mi.year >= 2014
GROUP BY mi.year
ORDER BY mi.year ASC;
# Over the centuries
SELECT
CASE
WHEN movie_info.year < 1930 THEN '1920s'
WHEN movie_info.year BETWEEN 1930 AND 1939 THEN '1930s'
WHEN movie_info.year BETWEEN 1940 AND 1949 THEN '1940s'
WHEN movie_info.year BETWEEN 1950 AND 1959 THEN '1950s'
WHEN movie_info.year BETWEEN 1960 AND 1969 THEN '1960s'
WHEN movie_info.year BETWEEN 1970 AND 1979 THEN '1970s'
WHEN movie_info.year BETWEEN 1980 AND 1989 THEN '1980s'
WHEN movie_info.year BETWEEN 1990 AND 1999 THEN '1990s'
WHEN movie_info.year BETWEEN 2000 AND 2009 THEN '2000s'
WHEN movie_info.year BETWEEN 2010 AND 2019 THEN '2010s'
ELSE '2020s'
END AS century,
AVG(bechdel_ratings.bechdel_pass) AS percent_b_pass
FROM bechdel_ratings
INNER JOIN movie_info
ON bechdel_ratings.movie_info_ID = movie_info.movie_info_ID
GROUP BY century
ORDER BY century ASC;
# Are specific countries/orig. languages doing particularly well/bad?
# Countries
# Bechdel 0-3 (min. 5 ratings)
SELECT country,
AVG(bechdel_score) AS avg_b_score
FROM bechdel_ratings
INNER JOIN movie_info
USING(movie_info_ID)
GROUP BY country
HAVING COUNT(bechdel_ID) > 5
ORDER BY avg_b_score DESC;
# Bechdel fail/pass (min. 5 ratings)
SELECT country,
AVG(bechdel_pass) AS percent_b_pass
FROM bechdel_ratings
INNER JOIN movie_info
USING(movie_info_ID)
GROUP BY country
HAVING COUNT(bechdel_ID) > 5
ORDER BY percent_b_pass DESC;
# Languages
# Bechdel 0-3 (min. 5 ratings)
SELECT original_language,
AVG(bechdel_score) AS avg_b_score
FROM bechdel_ratings
INNER JOIN movie_info
USING(movie_info_ID)
GROUP BY original_language
HAVING COUNT(bechdel_ID) > 5
ORDER BY avg_b_score DESC;
# Bechdel fail/pass (min. 5 ratings)
SELECT original_language,
AVG(bechdel_pass) AS percent_b_pass
FROM bechdel_ratings
INNER JOIN movie_info
USING(movie_info_ID)
GROUP BY original_language
HAVING COUNT(bechdel_ID) > 5
ORDER BY percent_b_pass DESC;