美文网首页
【SQL】12.SQLZOO练习7--More JOIN op

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

作者: 一曈 | 来源:发表于2017-06-05 15:12 被阅读49次

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

    题目 1
    SELECT id, title FROM movie
    WHERE yr=1962
    
    2
    select yr from movie
    where title='Citizen Kane';
    
    3
    select id,title,yr from movie 
    where title like'%Star Trek%'
    order by yr;
    
    4
    select id from actor
    where name='Glenn Close';
    
    5
    select id from movie 
    where title='Casablanca';
    
    6
    select name from actor
    join casting on id=actorid
    where movieid=11768;
    
    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';
    
    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'; 
    
    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; 
    
    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;
    
    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)
    
    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;
    
    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;
    
    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;
    
    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 op

          本文链接:https://www.haomeiwen.com/subject/pnvifxtx.html