-
Notifications
You must be signed in to change notification settings - Fork 0
/
MovieDataBase.sql
62 lines (48 loc) · 2.01 KB
/
MovieDataBase.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
-- Q1. List the films where the yr is 1962 [Show id, title]
SELECT id, title
FROM movie
WHERE yr=1962;
-- Q2. When was Citizen Kane released? Give year of 'Citizen Kane'.
SELECT yr
From movie
WHERE title = 'Citizen Kane';
-- Q3. List all of the Star Trek movies, include the id, title and yr
-- (all of these movies include the words Star Trek in the title). Order results by year.
SELECT id, title, yr
FROM movie
WHERE title LIKE '%Star Trek%';
--Q4. What id number does the actor 'Glenn Close' have?
SELECT id
FROM actor
WHERE name = 'Glenn Close';
-- Q5. What is the id of the film 'Casablanca'?
SELECT id
FROM movie
WHERE title = 'Casablanca';
-- Q6. Obtain the cast list for 'Casablanca'. Use movieid=11768, (or whatever value you got from the previous question)
SELECT name
FROM actor JOIN casting ON actor.id = casting.actorid
WHERE movieid = 11768;
-- Q7. Obtain the cast list for the film 'Alien'
SELECT name
FROM actor JOIN casting ON actor.id = casting.actorid
JOIN movie ON casting.movieid = movie.id
WHERE title = 'Alien';
-- Q8. List the films in which 'Harrison Ford' has appeared
SELECT title
FROM movie JOIN casting ON movie.id = casting.movieid
JOIN actor ON casting.actorid = actor.id
WHERE name = 'Harrison Ford';
-- Q9. List the films where 'Harrison Ford' has appeared - but not in the starring role.
-- [Note: the ord field of casting gives the position of the actor. If ord=1 then this actor is in the starring role]
SELECT title
FROM movie JOIN casting ON movie.id = casting.movieid
JOIN actor ON casting.actorid = actor.id
WHERE (name = 'Harrison Ford' AND ord <> 1);
-- Q10. List the films together with the leading star for all 1962 films.
SELECT title, actor.name
FROM movie JOIN casting ON movie.id = casting.movieid
JOIN actor ON casting.actorid = actor.id
WHERE (yr=1962 AND ord = 1);
-- Q11. Which were the busiest years for 'John Travolta',
-- show the year and the number of movies he made each year for any year in which he made more than 2 movies.