SQLZOO:More JOIN operations
2.Give year of ‘Citizen Kane’.
select yr FROM movie WHERE title='Citizen Kane';
3.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%' order by yr;
4.What id number does the actor ‘Glenn Close’ have?
select id from actor where name='Glenn Close';
5.What is the id of the film ‘Casablanca’
select id from movie where title='Casablanca';
6.Obtain the cast list for ‘Casablanca’.
what is a cast list?
The cast list is the names of the actors who were in the movie.
Use movieid=11768, (or whatever value you got from the previous question)
select name from actor join (movie join casting on id=movieid) on actor.id=actorid where title='Casablanca';
7.Obtain the cast list for the film ‘Alien’
select name from actor join (movie join casting on id=movieid) on actor.id=actorid where title='Alien';
8.List the films in which ‘Harrison Ford’ has appeared
select title from actor join (movie join casting on id=movieid) on actor.id=actorid where name='Harrison Ford';
9.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 actor join (movie join casting on id=movieid) on actor.id=actorid where name='Harrison Ford' and ord<>1 group by title;
10.List the films together with the leading star for all 1962 films.
select title,name from actor join (movie join casting on id=movieid) on actor.id=actorid where yr=1962 and ord=1;
11.Which were the busiest years for ‘Rock Hudson’, show the year and the number of movies he made each year for any year in which he made more than 2 movies.
SELECT yr,count(yr) from actor join (movie join casting on id=movieid) on actor.id=actorid where name='Rock Hudson' group by yr having count(yr)>2;
12.List the film title and the leading actor for all of the films ‘Julie Andrews’ played in.
Did you get “Little Miss Marker twice”?
Julie Andrews starred in the 1980 remake of Little Miss Marker and not the original(1934).
Title is not a unique field, create a table of IDs in your subquery
select title,name from actor join (movie join casting on id=movieid) on actor.id=actorid where movieid in (select movieid from actor join (movie join casting on id=movieid) on actor.id=actorid where name='Julie Andrews') and ord=1
13.Obtain a list, in alphabetical order, of actors who’ve had at least 15 starring roles.
select name from actor join (movie join casting on id=movieid) on actor.id=actorid where ord=1 group by name having count(name)>=15;
- 注意count语句的位置
14.List the films released in the year 1978 ordered by the number of actors in the cast, then by title.
select title,count(actorid) as num_actor from actor join (movie join casting on id=movieid) on actor.id=actorid where yr=1978 group by title order by num_actor desc,title;
15.List all the people who have worked with ‘Art Garfunkel’.
select name from actor join (movie join casting on id=movieid) on actor.id=actorid where movieid in (select movieid from actor join (movie join casting on id=movieid) on actor.id=actorid where name='Art Garfunkel') and name<>'Art Garfunkel';
- SQLZOO答案之【More JOIN operations】
- SQLZOO练习笔记-MORE JOIN OPERATIONS
- SQLZOO:More JOIN operations/zh 笔记
- sqlzoo练习答案--More JOIN operations
- SQLZOO(More JOIN operations)Writeup
- SQLZOO答案: More JOIN operations(全部通过)
- sqlzoo练习答案--More JOIN operations
- SQLZOO刷题练习:More JOIN operations
- SQLZOO More_JOIN_operations 答案 电影数据库
- mysql练习----More JOIN operations
- sqlzoo-The JOIN operation-solution(11\12\13小题)
- SQLZOO:Self join 笔记
- Git CMD - merge: Join two or more development histories together
- sqlzoo练习答案--The JOIN operation
- More about the Operations of string
- SQLZOO习题答案 The nobel table can be used to practice more SUM and COUNT functions./zh
- SQLZOO(self join)writeup未完
- SQLZOO练习笔记-the join operation
- SQLZOO:The JOIN operation/zh & Old JOIN Tutorial 笔记
- sqlzoo more join 题目及答案