More JOIN operations -- SQLZOO
The JOIN operation

注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道
01.List the films where the yr is 1962 [Show id, title]
译文:列出年上映时间为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 id, title 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的更多相关文章
- The JOIN operation -- SQLZOO
The JOIN operation 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.Modify it to show the matc ...
- mysql练习----More JOIN operations
This tutorial introduces the notion of a join. The database consists of three tables movie , actor a ...
- SQL练习六--More JOIN operations
movie Field name Type Notes id INTEGER An arbitrary unique identifier title CHAR(70) The name of the ...
- SQLZOO 习题
https://sqlzoo.net 8. 美國.印度和中國(USA, India, China)是人口又大,同時面積又大的國家.排除這些國家. 顯示以人口或面積為大國的國家,但不能同時兩者.顯示國家 ...
- Java Concurrency - Fork/Join Framework
Normally, when you implement a simple, concurrent Java application, you implement some Runnable obje ...
- sort merge join,hash join,netsloop join
Join Operations ? SORT-MERGE JOIN – Sorts tables on the join key and then merges them together – Sor ...
- Pandas -- Merge,join and concatenate
Merge, join, and concatenate pandas provides various facilities for easily combining together Series ...
- Python Pandas Merge, join and concatenate
Pandas提供了基于 series, DataFrame 和panel对象集合的连接/合并操作. Concatenating objects 先来看例子: from pandas import Se ...
- 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 ...
随机推荐
- 如何查看docker run启动参数命令
通过runlike去查看一个容器的docker run启动参数 安装pip yum install -y python-pip 安装runlike pip install runlike 查看dock ...
- 每日一题 - 剑指 Offer 46. 把数字翻译成字符串
题目信息 时间: 2019-07-02 题目链接:Leetcode tag: 动态规划 难易程度:中等 题目描述: 给定一个数字,我们按照如下规则把它翻译为字符串:0 翻译成 "a" ...
- 【Python3爬虫】破解时光网登录加密参数并实现模拟登录
一.站点分析 MTime 时光网是一个电影媒体与电商服务平台,而这次做的模拟登录则是依靠其手机端站点,站点地址为:https://m.mtime.cn/#.切换到登录页面,再分别输入账号和错误的密码, ...
- 小师妹学JVM之:JVM中的Safepoints
目录 简介 GC的垃圾回收器 分代回收器中的问题 safepoints safepoint一般用在什么地方 总结 简介 java程序员都听说过GC,大家也都知道GC的目的是扫描堆空间,然后将那些标记为 ...
- day54 js基础
目录 一.变量 二.数据类型 1 数值类型(number) 2 字符类型(string) 3 字符类型常用方法 4 布尔值(boolean) 5 null与undefined 6 对象 7 运算符 8 ...
- Idea 中 使用 devtools 热部署 spring-boot 应用 无需重新启动
描述: 在我们使用spring-boot开发时,如果在开发者调试项目,边修改边调试运行,如果每次修改 java文件或者配置文件后都需要重新启动程序,如果程序启动比较慢的化,每次修改一点东西都要重新启动 ...
- java 面向对象(十一):关键字:package/import
1.1 使用说明: * 1.为了更好的实现项目中类的管理,提供包的概念 * 2.使用package声明类或接口所属的包,声明在源文件的首行 * 3.包,属于标识符,遵循标识符的命名规则.规范(xxxy ...
- 数据可视化基础专题(十五):pyecharts 基础(二)flask 框架整合
Flask 前后端分离 Step 1: 新建一个 Flask 项目 $ mkdir pyecharts-flask-demo $ cd pyecharts-flask-demo $ mkdir tem ...
- 数据可视化实例(十二): 发散型条形图 (matplotlib,pandas)
https://datawhalechina.github.io/pms50/#/chapter10/chapter10 如果您想根据单个指标查看项目的变化情况,并可视化此差异的顺序和数量,那么散型条 ...
- c++运行程序 鼠标点击按钮 (c++)(windows)
简介 这是在黑漆漆的程序中,制造用户可点击的按钮,来决定程序下一步该作什么,的基本代码. 详解 头文件 <cstdio>和<windows.h> 结构体 //这不全别复制 st ...