【SQL】12.SQLZOO练习7--More JOIN operations

题目链接:https://sqlzoo.net/wiki/More_JOIN_operations

【SQL】12.SQLZOO练习7--More JOIN operations_第1张图片
题目
【SQL】12.SQLZOO练习7--More JOIN operations_第2张图片
1
SELECT id, title FROM movie
WHERE yr=1962
【SQL】12.SQLZOO练习7--More JOIN operations_第3张图片
2
select yr from movie
where title='Citizen Kane';
【SQL】12.SQLZOO练习7--More JOIN operations_第4张图片
3
select id,title,yr from movie 
where title like'%Star Trek%'
order by yr;
【SQL】12.SQLZOO练习7--More JOIN operations_第5张图片
4
select id from actor
where name='Glenn Close';
【SQL】12.SQLZOO练习7--More JOIN operations_第6张图片
5
select id from movie 
where title='Casablanca';
【SQL】12.SQLZOO练习7--More JOIN operations_第7张图片
6
select name from actor
join casting on id=actorid
where movieid=11768;
【SQL】12.SQLZOO练习7--More JOIN operations_第8张图片
7
select name from actor a
join (casting b,movie c) 
on a.id=b.actorid and b.movieid=c.id
where c.title='Alien';
【SQL】12.SQLZOO练习7--More JOIN operations_第9张图片
8
select title from movie a
join (actor b,casting c) on a.id=c.movieid and c.actorid=b.id
where b.name='Harrison Ford'; 
【SQL】12.SQLZOO练习7--More JOIN operations_第10张图片
9
select title from movie a
join (actor b,casting c) 
on a.id=c.movieid and c.actorid=b.id
where b.name='Harrison Ford' and c.ord !=1; 
【SQL】12.SQLZOO练习7--More JOIN operations_第11张图片
10
select a.title,b.name from movie a 
join (actor b,casting c) 
on a.id=c.movieid and b.id=c.actorid
where yr='1962' and c.ord=1;
【SQL】12.SQLZOO练习7--More JOIN operations_第12张图片
11
SELECT yr,COUNT(title) FROM movie a 
JOIN (casting b,actor c)ON a.id=b.movieid and b.actorid=c.id
where name='John Travolta'
GROUP BY yr
HAVING COUNT(title)=(SELECT MAX(count) FROM
(SELECT yr,COUNT(title) count FROM
movie a JOIN (casting b,actor c) ON a.id=b.movieid and b.actorid=c.id
where name='John Travolta'
GROUP BY yr) t)
【SQL】12.SQLZOO练习7--More JOIN operations_第13张图片
12
select a.title,b.name from movie a
join (actor b,casting c) on a.id=c.movieid and b.id=c.actorid
where movieid in 
(
select a.id from movie a 
join (casting b,actor c) on a.id=b.movieid and c.id = b.actorid 
where c.name='Julie Andrews')
and c.ord =1;
【SQL】12.SQLZOO练习7--More JOIN operations_第14张图片
13
select name from actor a
join (casting b,movie c) on a.id=b.actorid and c.id=b.movieid
where ord=1
group by name
having count(name)>=30;
【SQL】12.SQLZOO练习7--More JOIN operations_第15张图片
14
select title,count(actorid)
from movie a join (casting b,actor c) on a.id=b.movieid and c.id=b.actorid
where yr=1978
group by title
order by count(actorid)desc,title;
【SQL】12.SQLZOO练习7--More JOIN operations_第16张图片
15
select a.name from actor a
join (movie b,casting c) on a.id=c.actorid and b.id=c.movieid
where a.name !='Art Garfunkel'
and b.id IN
(select a.id from movie a
join (actor b,casting c) on a.id=c.movieid and b.id=c.actorid
where b.name='Art Garfunkel')

你可能感兴趣的:(【SQL】12.SQLZOO练习7--More JOIN operations)