SQL练习-SQLZOO SQLZOO:More JOIN operations


1.列出1962年首影的電影, [顯示 idtitle]

SELECT id,title
 FROM movie
 WHERE yr=1962

2.電影大國民 'Citizen Kane' 的首影年份。

select yr from movie
where title='Citizen Kane'

3.列出全部Star Trek星空奇遇記系列的電影,包括idtitle 和 yr(此系統電影都以Star Trek為電影名稱的開首)。按年份順序排列。

select id,title,yr from movie
where title like 'Star Trek%'

  
4.id是 11768, 11955, 21191 的電影是什麼名稱?

select title from movie
where id='11768'or id ='11955' or id='21191'

  
5.女演員'Glenn Close'的編號 id是什麼?

select id from actor
where name='Glenn Close'

6.電影北非諜影'Casablanca' 的編號 id是什麼?

select id from movie
where title='Casablanca' 

7.列出電影北非諜影 'Casablanca'的演員名單。

什麼是演員名單?

使用 movieid=11768, 這是你上一題得到的結果。

select name from actor,casting,movie 
where actor.id = casting.actorid and movie.id = casting.movieid and title = 'Casablanca'

8.顯示電影異型'Alien' 的演員清單。

select name from actor,casting 
where actor.id = casting.actorid and movieid = (select id from movie where title = 'Alien')

  
9.列出演員夏里遜福 'Harrison Ford' 曾演出的電影。

select title from movie join casting on movie.id=casting.movieid
where casting.actorid=(select id from actor where name='Harrison Ford')

10.列出演員夏里遜福 'Harrison Ford' 曾演出的電影,但他不是第1主角。

select title from movie join casting on movie.id=casting.movieid
where casting.actorid=(select id from actor where name='Harrison Ford') and ord >1

11.列出1962年首影的電影及它的第1主角。

select title,name from movie join casting on movie.id=casting.movieid join actor on casting.actorid = actor.id
where yr=1962 and ord=1

  

猜你喜欢

转载自www.cnblogs.com/cat30/p/12975210.html