-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay_4_Task_4_Questions.sql
More file actions
56 lines (46 loc) · 1.58 KB
/
Day_4_Task_4_Questions.sql
File metadata and controls
56 lines (46 loc) · 1.58 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
--Questions
-- 4.1 Select the title of all movies.
SELECT Title
FROM Movies
-- 4.2 Show all the distinct ratings in the database.
SELECT DISTINCT Rating
FROM Movies
-- 4.3 Show all unrated movies.
-- from https://www.sqlitetutorial.net/sqlite-is-null/
SELECT Title
FROM Movies
WHERE Rating IS NULL
-- 4.4 Select all movie theaters that are not currently showing a movie.
SELECT Name
FROM MovieTheaters
WHERE Movie IS NULL
-- 4.5 Select all data from all movie theaters and, additionally, the data from the movie that is being shown in the theater (if one is being shown).
SELECT MovieTheaters.*, Movies.*
FROM MovieTheaters
LEFT JOIN Movies
ON MovieTheaters.Movie = Movies.Code
-- 4.6 Select all data from all movies and, if that movie is being shown in a theater, show the data from the theater.
SELECT Movies.*, MovieTheaters.*
FROM Movies
LEFT JOIN MovieTheaters
ON MovieTheaters.Movie = Movies.Code
-- 4.7 Show the titles of movies not currently being shown in any theaters.
SELECT Movies.Title
FROM Movies
LEFT JOIN MovieTheaters
ON MovieTheaters.Movie = Movies.Code
WHERE MovieTheaters.Code IS NULL
-- 4.8 Add the unrated movie "One, Two, Three".
INSERT INTO Movies(Title,Rating) VALUES('One, Two, Three',NULL);
-- 4.9 Set the rating of all unrated movies to "G".
UPDATE Movies
SET Rating = 'G'
WHERE Rating IS NULL
-- 4.10 Remove movie theaters projecting movies rated "NC-17".
DELETE FROM MovieTheaters
WHERE MovieTheaters.Name= (
SELECT MovieTheaters.Name
FROM MovieTheaters
JOIN Movies
ON MovieTheaters.Movie = Movies.Code
Where Rating = 'NC-17')