|
|
@@ -1,28 +1,28 @@
|
|
1
|
|
-INSERT into movies
|
|
|
1
|
+INSERT into movies (title, runtime, genre, imdb_score, rating)
|
|
2
|
2
|
VALUES ('Howard the Duck', 110, 'Sci-Fi', 4.6, 'PG');
|
|
3
|
3
|
|
|
4
|
|
-INSERT into movies
|
|
|
4
|
+INSERT into movies (title, runtime, genre, imdb_score, rating)
|
|
5
|
5
|
VALUES ('Lavalantula', 83, 'Horror', 4.7, 'TV-14');
|
|
6
|
6
|
|
|
7
|
|
-INSERT into movies
|
|
|
7
|
+INSERT into movies (title, runtime, genre, imdb_score, rating)
|
|
8
|
8
|
VALUES ('Starship Troopers', 129, 'Sci-Fi', 7.2, 'PG-13');
|
|
9
|
9
|
|
|
10
|
|
-INSERT into movies
|
|
|
10
|
+INSERT into movies (title, runtime, genre, imdb_score, rating)
|
|
11
|
11
|
VALUES ('Waltz With Bashir', 90, 'Documentary', 8.0, 'R');
|
|
12
|
12
|
|
|
13
|
|
-INSERT into movies
|
|
|
13
|
+INSERT into movies (title, runtime, genre, imdb_score, rating)
|
|
14
|
14
|
VALUES ('Spaceballs', 96, 'Comedy', 7.1, 'PG');
|
|
15
|
15
|
|
|
16
|
|
-INSERT into movies
|
|
|
16
|
+INSERT into movies (title, runtime, genre, imdb_score, rating)
|
|
17
|
17
|
VALUES ('Monsters Inc.', 92, 'Animation', 8.1, 'G');
|
|
18
|
18
|
|
|
19
|
|
-INSERT into movies
|
|
|
19
|
+INSERT into movies (title, runtime, genre, imdb_score, rating)
|
|
20
|
20
|
VALUES ('Finding Nemo', 101, 'Animation', 8.1, 'G');
|
|
21
|
21
|
|
|
22
|
|
-INSERT into movies
|
|
|
22
|
+INSERT into movies (title, runtime, genre, imdb_score, rating)
|
|
23
|
23
|
VALUES ('Just Go With It', 117, 'Comedy', 6.4, 'PG-13');
|
|
24
|
24
|
|
|
25
|
|
-INSERT into movies
|
|
|
25
|
+INSERT into movies (title, runtime, genre, imdb_score, rating)
|
|
26
|
26
|
VALUES ('Dodgeball', 117, 'Comedy', 6.7, 'PG-13');
|
|
27
|
27
|
|
|
28
|
28
|
SELECT *
|
|
|
@@ -33,33 +33,35 @@ SELECT *
|
|
33
|
33
|
FROM movies
|
|
34
|
34
|
WHERE imdb_score >= 6.5;
|
|
35
|
35
|
|
|
36
|
|
-SELECT *
|
|
|
36
|
+SELECT *
|
|
37
|
37
|
FROM movies
|
|
38
|
38
|
WHERE rating = 'G' OR rating = 'PG'
|
|
39
|
39
|
AND runtime < 100;
|
|
40
|
40
|
|
|
41
|
41
|
-- avg runtimes of movies rated below 7.5, grouped by genre
|
|
42
|
|
-Select AVG(runtime)
|
|
43
|
|
-from movies
|
|
44
|
|
-where rating < 7.5
|
|
|
42
|
+SELECT AVG(runtime)
|
|
|
43
|
+FROM movies
|
|
|
44
|
+WHERE rating < 7.5
|
|
45
|
45
|
GROUP BY genre;
|
|
46
|
46
|
|
|
47
|
|
-Update movies
|
|
48
|
|
-Set rating = 'R'
|
|
|
47
|
+UPDATE movies
|
|
|
48
|
+SET rating = 'R'
|
|
49
|
49
|
WHERE title = 'Starship Troopers';
|
|
50
|
50
|
|
|
51
|
|
-Select id, rating, title
|
|
|
51
|
+SELECT id, rating, title
|
|
52
|
52
|
FROM movies
|
|
53
|
|
-Where Genre = 'Horror' AND Genre = 'Documentary';
|
|
|
53
|
+WHERE Genre = 'Horror' AND Genre = 'Documentary';
|
|
54
|
54
|
|
|
55
|
55
|
-- avg min max IMBD score for movies of each rating
|
|
56
|
|
-Select MIN(imdb_score), MAX(imbd_score), AVG(imbd_score)
|
|
57
|
|
-from movies
|
|
58
|
|
-having count(*) > 1;
|
|
59
|
|
-
|
|
60
|
|
-
|
|
|
56
|
+SELECT rating, MIN(imdb_score) as "MIN IMDB SCORE", MAX(imdb_score) as "MAX IMDB SCORE", ROUND(AVG(imdb_score), 2) as "AVG IMDB SCORE", COUNT(*) as "NUM MOVIES"
|
|
|
57
|
+FROM movies
|
|
|
58
|
+GROUP BY rating;
|
|
61
|
59
|
|
|
|
60
|
+-- Use HAVING COUNT(*) > 1
|
|
|
61
|
+SELECT rating, MIN(imdb_score) as "MIN IMDB SCORE", MAX(imdb_score) as "MAX IMDB SCORE", ROUND(AVG(imdb_score), 2) as "AVG IMDB SCORE"
|
|
|
62
|
+FROM movies
|
|
|
63
|
+GROUP BY rating
|
|
|
64
|
+HAVING count(*) > 1;
|
|
62
|
65
|
|
|
63
|
|
-Delete from movies
|
|
|
66
|
+DELETE FROM movies
|
|
64
|
67
|
WHERE rating = 'R';
|