SqlZoo.net习题答案:The Join 【Movie】

习题地址:http://sqlzoo.net/3.htm

 

表结构:  movie(id, title, yr, director)
      actor(id, name)
      casting(movieidactorid, ord)

 

1b.Give year of 'Citizen Kane'.

select yr 
from movie
where title = 'Citizen Kane'

 

1c.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.)

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

 

2a.What are the titles of the films with id 11768, 11955, 21191

select title
from movie
where id in (11768, 11955, 21191)

 

2b.What id number does the actor 'Glenn Close' have?

select id
from actor
where name = 'Glenn Close'

 

2c.What is the id of the film 'Casablanca'

select id
from movie
where title = 'Casablanca'

 

3a.Obtain the cast list for 'Casablanca'. Use the id value that you obtained in the previous question.

select actor.name
from actor join casting on (actor.id= casting.actorid)
where casting.movieid = 11768

 

3b.Obtain the cast list for the film 'Alien'

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

 

3c.List the films in which 'Harrison Ford' has appeared

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

 

3d.List the films where 'Harrison Ford' has appeared - but not in the star 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 movie.title
from movie join casting on (movie.id = casting.movieid)
where casting.actorid = (select actor.id from actor where actor.name = 'Harrison Ford')  and  casting.ord <> 1

 

3e.List the films together with the leading star for all 1962 films.

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

 

4a.Which were the busiest years for 'John Travolta'. Show the number of movies he made for each year.

select movie.yr, count(movie.id)
from movie join casting on (movie.id = casting.movieid) join actor on (actor.id = casting.actorid) where actor.name = 'John Travolta' 
group by movie.yr
having count(movie.id) >= all (select count(movie.id) from movie join casting on (movie.id = casting.movieid) join actor on (actor.id = casting.actorid) where actor.name = 'John Travolta' 
group by movie.yr)

 

 

4b.List the film title and the leading actor for all of 'Julie Andrews' films.

select movie.title, actor.name
from movie join casting on (movie.id = casting.movieid)
join actor on (actor.id = casting.actorid)
where casting.ord = 1
group by movie.id
having 
movie.id in (select movie.id from movie
join casting on (movie.id = casting.movieid)
join actor on (actor.id = casting.actorid)
where actor.name = 'Julie Andrews')

 

 

4c.Obtain a list of actors in who have had at least 30 starring roles.

select actor.name
from actor join casting on (actor.id = casting.actorid) join movie on (movie.id = casting.movieid) where casting.ord = 1
group by actor.id
having count(movie.id) >= 30

 

 

4d.List the 1978 films by order of cast list size.

select movie.title, count(actor.id)
from movie join casting on (movie.id = casting.movieid) join actor on (actor.id = casting.actorid) 
where movie.yr = 1978 
group by movie.title
order by 2 desc

 

 

4e.List all the people who have worked with 'Art Garfunkel'.

select  distinct actor.name 
from actor join casting on (actor.id = casting.actorid) join movie on (movie.id = casting.movieid) where movie.id in  
(select movie.id from movie join casting on (movie.id = casting.movieid) join actor on (actor.id = casting.actorid) where actor.name = 'Art Garfunkel') and actor.name <> 'Art Garfunkel'

 

 

转载于:https://www.cnblogs.com/Leo-Forest/archive/2012/06/02/2531799.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/549749.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

汉语编程++

没想到汉语编程又有人开始网上对骂了。一方指另一方骗人&#xff0c;一方吹自已伟大。今天群里头有人又把它翻出来了&#xff0c;刚好无聊&#xff0c;也就发明了一个汉语编程语言&#xff0c;集成到visual studio 2005的IDE中&#xff0c;名字就叫汉语编程&#xff0c;欢迎同样…

hightopo学习系列:hightopo介绍(一)

起因 新的软件主管来公司以后&#xff0c;有整整2周的时间没有搭理前端开发。就在这周一快下班的时候&#xff0c;突然和我说话了。问了我一些以前用的图形库&#xff0c;并让我开始了解hightopo。甩给了我一个全拼&#xff0c;就拂袖而去&#xff0c;留下一脸懵逼的我。 没办…

mongo指令

use admin db.runCommand({logRotate:1}) show dbs; db.currentOp(); db.serverStatus().connections db.killOp(26593769); use adbname db.tblname.ensureIndex({"sendtime":1}) db.tblname.getIndex() 转载于:https://www.cnblogs.com/ccgblog/p/8427972.html

女人,向《奋斗》中的夏琳米莱们学习什么

被称为赵宝刚导演的转型之作电视连续剧《奋斗》&#xff0c;看得我有些意犹未尽。据说佟大为与马伊俐都是本色表演&#xff0c;但是我却更喜欢剧中米莱的角色。 刚开始看《奋斗》的时候&#xff0c;以为夏琳是许晴演的呢&#xff0c;从长相性格表情连发型都像&#xff0c;像缩小…

vue项目积累

工作记录 1.修饰符及其使用 最近项目上看到这样的代码&#xff1a; child组件隐藏模态框触发以下事件 closeHandler () {this.$emit(update:open, false)},查阅资料发现&#xff0c;这是以修饰符的方式实现了“双向绑定”&#xff0c;避免了真正的双向绑定会带来维护上的问题。…

OpenCV4Android Tutorial0解析

Tutorial0是一个纯粹的android程序&#xff0c;没有opencv部分&#xff0c;是其他程序的框架基础。 有Sample0Base.java, Sample0View.java&#xff0c; SampleViewBase.java.三个文件。 Sample0Base 是程序入口&#xff0c;主要设置surfaceview和菜单。 requestWindowFeature(…

NPM管理

npm 发布流程 npm loginnpm versionnpm publish npm version npm version <update_type> // types: patch, major, or minor主版本号&#xff08;Major&#xff09;.次版本号&#xff08;Minor&#xff09;.修订号&#xff08;Patch&#xff09; 版本号递增规则: 主版…

网络工程师应掌握的50个路由器知识要点

1、什么时候使用多路由协议?  当两种不同的路由协议要交换路由信息时&#xff0c;就要用到多路由协议。当然&#xff0c;路由再分配也可以交换路由信息。下列情况不必使用多路由协议:  从老版本的内部网关协议( Interior Gateway Protocol&#xff0c;I G P)升级到新版本的…

Unity工程无代码化

目的 Unity默认是将代码放入工程&#xff0c;这样容易带来一些问题。1. 代码和资源混合&#xff0c;职能之间容易互相误改。2. 当代码量膨胀到一定程度后&#xff0c;代码的编译时间长到无法忍受。新版的unity支持通过asmdef来将代码分成多个dll工程&#xff0c;有所缓解。所以…

曾国藩传 读后感

转载于:https://www.cnblogs.com/eat-too-much/p/11335113.html

hdu 1102 pku 2421 解题报告

这题很简单&#xff0c;我差不多15分钟就写好代码了&#xff0c;运行结果也是正确的。可提交就是RE&#xff0c;百思不得其解&#xff0c;调了两个小时的时候&#xff0c;我才忽然发现我存边的时候数组开小了&#xff0c;我当时也想到肯定是数组问题&#xff0c;但是我却忽律了…

深入C#学习系列一:序列化(Serialize)、反序列化(Deserialize)

深入C#学习系列一&#xff1a;序列化(Serialize)、反序列化(Deserialize) 序列化又称串行化&#xff0c;是.NET运行时环境用来支持用户定义类型的流化的机制。其目的是以某种存储形成使自定义对象持久化&#xff0c;或者将这种对象从一个地方传输到另一个地方。.NET框架提供了两…

分别用 数组和链表处理约瑟夫环问题

#include <stdio.h> #include <stdlib.h> int main() { int k0,n0,s0,m0; //k为1,2,3报数时的计数变量,m为退出人数 int num [100]; int *pnum; int i; printf("Enter the number of person and the key:"); scanf("%d%d",&n,…

QT_环境搭建

QT_环境搭建 Qt软件安装&#xff1a;https://www.jianshu.com/p/65bc892829a0 Qt软件下载&#xff1a;https://mirrors.tuna.tsinghua.edu.cn/qt/official_releases/qt/5.13/5.13.0/ 转载于:https://www.cnblogs.com/panda-w/p/11338742.html

十一月·飘·立冬

十一月的南粤叶依然青翠在枝头与秋风和舞落叶遍地的诗意画面在博客生活逝如流年 渐走渐淡回忆飘然而来又飘然而去秋的最后一天放下回忆 飘去天涯飘不要说也不要问目光交错的一瞬注定了今生缘分此情可以见真心春风急 秋风也狠乱乱纷纷 是红尘浮浮沉沉 似幻似真金枝玉叶的结…

OCP-052考试题库汇总(27)-CUUG内部解答版

Which two of these must be available READ/WRITE to keep a database open? A)all copies of the control file. B)the password file. C)all members of the current redo log group. D)spfile. E)TEMP tablespace F)SYSAUX tablespace Answer: AC 转载于:https://www.cnbl…

07/11/10 资料整理

脉码调制PMC T1 E1 T2 T32007-10-31 10:39什么是T1? 北美的24路脉码调制PCM简称T1&#xff0c;速率是1.544Mbit/s 我国采用的是欧洲的T1标准。北美使用的T1系统共有24个话路&#xff0c;每个话路采样脉冲用7bit编码&#xff0c;然后再加上1位信令码元&#xff0c;因此一个话路…

printf \r \n

简介 \r 回到这一行的开始处 \n 换下一行 参考链接 csdn 转载于:https://www.cnblogs.com/eat-too-much/p/11339935.html

真正的累

真正的累&#xff0c;是从骨头里泛出来的一丝丝的酸软&#xff0c;先是在后背盘旋&#xff0c;不痒也不痛&#xff0c;就是不舒服。然后身上热烘烘的&#xff0c;就着这热气&#xff0c;那些酸软就从后背发散开来。眼睛也会有点酸&#xff0c;闭上眼睛就会很舒服。你不得不挺直…

OCP-052考试题库汇总(28)-CUUG内部解答版

Archivelog mode is enabled for your database and DB_CREATE_FILE_DEST is set to ‘/u01/oracle/db01’. The parameters, DB_CREATE_ONLINE_LOG_DEST_n and DB_RECOVERY_FILE_DEST, and not specified. Which four are stored in the location specified by DB_CREATE_FILE…