-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsql_queries.sql
More file actions
51 lines (43 loc) · 1.16 KB
/
sql_queries.sql
File metadata and controls
51 lines (43 loc) · 1.16 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
-- Table structure
-- movie actor casting
-- id id movieid
-- title name actorid
-- yr ord
-- director
-- budget
-- gross
-- List the film title and the leading actor for all of the films 'Julie Andrews' played in.
SELECT title, name
FROM movie, casting, actor
WHERE movieid=movie.id
AND actorid=actor.id
AND ord=1
AND movieid IN
(SELECT movieid FROM casting, actor
WHERE actorid=actor.id
AND name='Julie Andrews')
-- Obtain a list, in alphabetical order, of actors who've had at least 30 starring roles.
SELECT name
FROM casting JOIN actor
ON actorid = actor.id
WHERE ord=1
GROUP BY name
HAVING COUNT(movieid)>=30
-- List the films released in the year 1978 ordered by the number of actors in the cast.
Select title, count(*) as 'number_of_actors'
From movie Join casting
On id = movieid
Where yr = '1978'
Group by title
Order by COUNT(actorid) desc
-- List all the people who have worked with 'Art Garfunkel'.
Select name
From actor Join casting
On id = actorid
Where movieid in
(Select movieid
From casting Join actor
On id = actorid
Where name = 'Art Garfunkel')
And name != 'Art Garfunkel'
Order by name