The JOIN operation

注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道

01.List the films where the yr is 1962 [Show idtitle]

译文:列出年上映时间为1962年的电影(显示id,片名)

SELECT id, title FROM movie WHERE yr=1962;

02.Give year of 'Citizen Kane'.

译文:请说出《公民凯恩》年份。

SELECT yr FROM movie WHERE title = 'Citizen Kane';

03.List all of the Star Trek movies, include the idtitle and yr (all of these movies include the words Star Trek in the title). Order results by year.

译文:列出所有的《星际迷航》电影,包括id、标题和yr(所有这些电影的标题中都包含《星际迷航》这个单词)。订单结果逐年递增。

SELECT id, title, yr FROM movie WHERE title LIKE 'Star Trek%' 

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

译文:演员“格伦·克洛斯”的身份证号码是多少

SELECT title FROM movie WHERE id IN (11768, 11955, 21191)

05.What is the id of the film 'Casablanca'

译文:电影《卡萨布兰卡》的主题是什么?

SELECT id FROM actor WHERE name LIKE 'Glenn Close'

06.Obtain the cast list for 'Casablanca'.what is a cast list?Use movieid=11768, (or whatever value you got from the previous question)

译文:获取《卡萨布兰卡》的演员名单。什么是演员名单?使用movieid=11768,(或从上一个问题中得到的任何值)

SELECT id FROM movie WHERE title LIKE 'Casablanca'

07.Obtain the cast list for the film 'Alien'

译文:获取电影《异形》的演员名单

SELECT name FROM actor WHERE id IN ( SELECT actorid FROM movie m JOIN casting c ON m.id = c.movieid WHERE id = 11768)

08.List the films in which 'Harrison Ford' has appeared

译文:列出哈里森·福特出演过的电影

SELECT name FROM actor WHERE id IN ( SELECT actorid FROM movie m JOIN casting c ON m.id = c.movieid WHERE id = ( SELECT id FROM movie WHERE title LIKE 'Alien'))

09.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]

译文:列出“哈里森·福特”出演过的电影,但不包括主演的电影。[注:cast的ord字段给出了演员的位置。如果ord=1,则表示该演员在主演角色]

SELECT title FROM movie m JOIN casting c ON (m.id= c.movieid) WHERE c.actorid IN( SELECT id FROM actor WHERE name = 'Harrison Ford')

10.List the films together with the leading star for all 1962 films.

译文:列出1962年所有电影的电影和主演

SELECT title FROM movie m JOIN casting c ON (m.id= c.movieid) WHERE c.ord != 1 AND c.actorid IN( SELECT id FROM actor WHERE name = 'Harrison Ford')

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.

译文:哪一年是“洛克·哈德逊”最繁忙的年份,展示他每年制作超过2部电影的电影数量。

SELECT yr,COUNT(title) FROM movie JOIN casting ON movie.id=movieid JOIN actor ON actorid=actor.id WHERE name='John Travolta' GROUP BY yr HAVING COUNT(title) > 2;

12.List the film title and the leading actor for all of the films 'Julie Andrews' played in.

译文:请列出“朱莉·安德鲁斯”参演的所有影片的片名和男主角。

SELECT title, name FROM casting JOIN movie ON movie.id = casting.movieid JOIN actor ON casting.actorid = actor.id WHERE movieid IN (SELECT movieid FROM casting WHERE actorid IN ( SELECT id FROM actor WHERE name='Julie Andrews')) AND ord = 1;

13.Obtain a list, in alphabetical order, of actors who've had at least 15 starring roles.

译文:获得一个至少扮演过15个角色的演员名单,按字母顺序排列。

SELECT name FROM actor WHERE id IN(SELECT actorid FROM casting WHERE ord = 1 GROUP BY actorid HAVING COUNT(*) >= 30);

14.List the films released in the year 1978 ordered by the number of actors in the cast, then by title.

译文:列出1978年上映的电影,按演员数量排序,然后按片名排序。

SELECT title, COUNT(actorid) AS num
FROM casting JOIN movie ON id = movieid
WHERE yr= 1978
GROUP BY movieid, title
ORDER BY num DESC, title;

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

译文:列出所有与“阿特·加芬克尔”共事过的人。

SELECT name
FROM actor JOIN casting ON id = actorid
WHERE name <> 'Art Garfunkel'
AND movieid IN
SELECT movieid FROM casting
WHERE actorid IN (SELECT id FROM actor WHERE name = 'Art Garfunkel'));

练习网址:https://sqlzoo.net/wiki/More_JOIN_operations

——————————————————————————————————————————————————————————————————————————————————————————————————————————

More JOIN operations -- SQLZOO的更多相关文章

  1. The JOIN operation -- SQLZOO

    The JOIN operation 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.Modify it to show the matc ...

  2. mysql练习----More JOIN operations

    This tutorial introduces the notion of a join. The database consists of three tables movie , actor a ...

  3. SQL练习六--More JOIN operations

    movie Field name Type Notes id INTEGER An arbitrary unique identifier title CHAR(70) The name of the ...

  4. SQLZOO 习题

    https://sqlzoo.net 8. 美國.印度和中國(USA, India, China)是人口又大,同時面積又大的國家.排除這些國家. 顯示以人口或面積為大國的國家,但不能同時兩者.顯示國家 ...

  5. Java Concurrency - Fork/Join Framework

    Normally, when you implement a simple, concurrent Java application, you implement some Runnable obje ...

  6. sort merge join,hash join,netsloop join

    Join Operations ? SORT-MERGE JOIN – Sorts tables on the join key and then merges them together – Sor ...

  7. Pandas -- Merge,join and concatenate

    Merge, join, and concatenate pandas provides various facilities for easily combining together Series ...

  8. Python Pandas Merge, join and concatenate

    Pandas提供了基于 series, DataFrame 和panel对象集合的连接/合并操作. Concatenating objects 先来看例子: from pandas import Se ...

  9. left outer join preserving unmatched rows from the first table

    https://docs.oracle.com/javadb/10.8.3.0/ref/rrefsqlj18922.html INNER JOIN operation Specifies a join ...

随机推荐

  1. C++版的网络数据包解析策略(升级版)

    初版:http://www.cnblogs.com/wjshan0808/p/6580638.html 说明:在实现了对应的接口后该策略可以适合绝大多数的网络数据包结构 首先,是三个接口 IProdu ...

  2. css transparent属性_css 透明颜色transparent的使用

    在css中 transparent到底是什么意思呢? transparent 它代表着全透明黑色,即一个类似rgba(0,0,0,0)这样的值. 例如在css属性中定义:background:tran ...

  3. 02.RabbitMQ整合springboot简单使用

    1.添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

  4. 微软全球资深副总裁对 VS Code 黑宝书的推荐序!VS Code 月活用户已达 1200 万!

    前不久,首本 VS Code 中文书终于问世了! 在本书出版之前,我很高兴能邀请到微软全球资深副总裁 Julia Liuson 为本书写推荐序!下面,我们就来看一下 Julia 所写的推荐序的完整内容 ...

  5. Linux进程监控命令

    最近使用centos在建站,没有用市面上的什么服务商的服务器,自己用树莓派3B+建了这个博客.但是发现经常宕机,所以想看看服务器在干什么,百度了很久,发现vmstat命令不错,拿出来推荐推荐. 这是我 ...

  6. BFC原理解析

    BFC的概念 块格式化上下文(Block Formatting Context,BFC) 是Web页面的可视化CSS渲染的一部分,是块盒子的布局过程发生的区域,也是浮动元素与其他元素交互的区域. 它是 ...

  7. 谈谈你对 TCP 三次握手和四次挥手的理解

    TCP三次握手: 1.客户端发送syn包到服务器,等待服务器确认接收. 2.服务器确认接收syn包并确认客户的syn,并发送回来一个syn+ack的包给客户端. 3.客户端确认接收服务器的syn+ac ...

  8. Celery无法注册任务的几种情况

    Celery处理异步任务使得程序不必等待任务结束就可以继续执行其它任务或返回数据结果, 在处理耗时任务如发送邮件.发送信息验证码等场景下非常适用! Celery使用方法灵活,根据具体业务有不同的部署和 ...

  9. node最简单的本地服务搭建

    **1.首先需要安装node** [node下载链接](http://nodejs.cn/download/)**2.需要安装http的镜像文件** npm install http-server - ...

  10. 拦截器(Interceptor)中的invocation.invoke()是什么意思?

    拦截器(Interceptor)中的invocation.invoke()是什么意思? 最佳答案: invocation.invoke() 就是通知struts2接着干下面的事情 比如 调用下一个拦截 ...