SQLZOO练习-- More JOIN operations(含题目翻译)

2023-10-07 23:10

本文主要是介绍SQLZOO练习-- More JOIN operations(含题目翻译),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

知识点

join on连接(两个表、三个表),join+子查询

 

数据表

表的连接关系

  • movie.id = casting.movieid
  • actor.id = casting.actorid

说明

  1. movie:电影id、电影名称、上映年份、导演、预算、票房
  2. actor:演员id、演员
  3. casting:电影id、演员id、主演标识(1代表主演)

 

题目内容

1.List the films where the yr is 1962 [Show id, title].(查询上映年份为1962年的电影id和电影名称)

select id, title from movie
where yr=1962

 

 

2.Give year of 'Citizen Kane'.(查询电影‘Citizen Kane’的上映年份)

select yr from movie
where title = 'Citizen Kane'

 

 

3.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.(查询名称包含‘Star Trek’的电影id、电影名称、上映年份)

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

 

 

4.What id number does the actor 'Glenn Close' have?(查询演员'Glenn Close'的演员id)

select id from actor
where name = 'Glenn Close'

 

 

5.What is the id of the film 'Casablanca'.(查询电影 'Casablanca'的电影id)

select id from movie
where title = 'Casablanca'

 

 

6.Obtain the cast list for 'Casablanca'(movieid=11768).(查询电影 'Casablanca'的演员)

select name 
from actor join casting on actor.id = casting.actorid
and movieid = 11768

 

 

7.Obtain the cast list for the film 'Alien'.(查询电影 'Alien'的演员)

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

 

 

8.List the films in which 'Harrison Ford' has appeared.(查询'Harrison Ford'参加过的电影)

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

 

 

9.List the films where 'Harrison Ford' has appeared - but not in the starring role. (查询'Harrison Ford'参加但不担任主演的电影)

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

 

10.List the films together with the leading star for all 1962 films.(查询1962年的电影以及电影主演)

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

 

 

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.(查询'Rock Hudson'在一年里参加超过2部电影的年份,以及参加的电影数量)

select yr,count(title)
from casting join movie on casting.movieid = movie.id 
join actor on casting.actorid = actor.id
and name = 'Rock Hudson'
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 distinct(title),name 
from movie join casting on movie.id=movieid
join actor on actorid=actor.id 
and ord=1
and movieid in (select t2.movieid from actor t1  join casting t2 on t2.actorid=t1.id and name='Julie Andrews')

 

 

13.Obtain a list, in alphabetical order, of actors who've had at least 15 starring roles.(查询担任过15个以上电影主演的演员)

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

 

 

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) 
from movie join casting on movie.id = casting.movieid
and movie.yr = 1978
group by title 
order by count(actorid) desc,title

 

 

15.List all the people who have worked with 'Art Garfunkel'.(查询与演员 'Art Garfunkel'合作过的演员)

select name 
from actor join casting on actor.id = casting.actorid
and name !=  'Art Garfunkel'
and movieid in (select movieidfrom actor join casting on actor.id = casting.actoridand actor.name = 'Art Garfunkel')

 

这篇关于SQLZOO练习-- More JOIN operations(含题目翻译)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/161066

相关文章

RabbitMQ练习(AMQP 0-9-1 Overview)

1、What is AMQP 0-9-1 AMQP 0-9-1(高级消息队列协议)是一种网络协议,它允许遵从该协议的客户端(Publisher或者Consumer)应用程序与遵从该协议的消息中间件代理(Broker,如RabbitMQ)进行通信。 AMQP 0-9-1模型的核心概念包括消息发布者(producers/publisher)、消息(messages)、交换机(exchanges)、

论文翻译:arxiv-2024 Benchmark Data Contamination of Large Language Models: A Survey

Benchmark Data Contamination of Large Language Models: A Survey https://arxiv.org/abs/2406.04244 大规模语言模型的基准数据污染:一项综述 文章目录 大规模语言模型的基准数据污染:一项综述摘要1 引言 摘要 大规模语言模型(LLMs),如GPT-4、Claude-3和Gemini的快

题目1254:N皇后问题

题目1254:N皇后问题 时间限制:1 秒 内存限制:128 兆 特殊判题:否 题目描述: N皇后问题,即在N*N的方格棋盘内放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在同一斜线上。因为皇后可以直走,横走和斜走如下图)。 你的任务是,对于给定的N,求出有多少种合法的放置方法。输出N皇后问题所有不同的摆放情况个数。 输入

题目1380:lucky number

题目1380:lucky number 时间限制:3 秒 内存限制:3 兆 特殊判题:否 提交:2839 解决:300 题目描述: 每个人有自己的lucky number,小A也一样。不过他的lucky number定义不一样。他认为一个序列中某些数出现的次数为n的话,都是他的lucky number。但是,现在这个序列很大,他无法快速找到所有lucky number。既然

【Rust练习】12.枚举

练习题来自:https://practice-zh.course.rs/compound-types/enum.html 1 // 修复错误enum Number {Zero,One,Two,}enum Number1 {Zero = 0,One,Two,}// C语言风格的枚举定义enum Number2 {Zero = 0.0,One = 1.0,Two = 2.0,}fn m

MySql 事务练习

事务(transaction) -- 事务 transaction-- 事务是一组操作的集合,是一个不可分割的工作单位,事务会将所有的操作作为一个整体一起向系统提交或撤销请求-- 事务的操作要么同时成功,要么同时失败-- MySql的事务默认是自动提交的,当执行一个DML语句,MySql会立即自动隐式提交事务-- 常见案例:银行转账-- 逻辑:A给B转账1000:1.查询

论文翻译:ICLR-2024 PROVING TEST SET CONTAMINATION IN BLACK BOX LANGUAGE MODELS

PROVING TEST SET CONTAMINATION IN BLACK BOX LANGUAGE MODELS https://openreview.net/forum?id=KS8mIvetg2 验证测试集污染在黑盒语言模型中 文章目录 验证测试集污染在黑盒语言模型中摘要1 引言 摘要 大型语言模型是在大量互联网数据上训练的,这引发了人们的担忧和猜测,即它们可能已

html css jquery选项卡 代码练习小项目

在学习 html 和 css jquery 结合使用的时候 做好是能尝试做一些简单的小功能,来提高自己的 逻辑能力,熟悉代码的编写语法 下面分享一段代码 使用html css jquery选项卡 代码练习 <div class="box"><dl class="tab"><dd class="active">手机</dd><dd>家电</dd><dd>服装</dd><dd>数码</dd><dd

【408数据结构】散列 (哈希)知识点集合复习考点题目

苏泽  “弃工从研”的路上很孤独,于是我记下了些许笔记相伴,希望能够帮助到大家    知识点 1. 散列查找 散列查找是一种高效的查找方法,它通过散列函数将关键字映射到数组的一个位置,从而实现快速查找。这种方法的时间复杂度平均为(

014.Python爬虫系列_解析练习

我 的 个 人 主 页:👉👉 失心疯的个人主页 👈👈 入 门 教 程 推 荐 :👉👉 Python零基础入门教程合集 👈👈 虚 拟 环 境 搭 建 :👉👉 Python项目虚拟环境(超详细讲解) 👈👈 PyQt5 系 列 教 程:👉👉 Python GUI(PyQt5)文章合集 👈👈 Oracle数据库教程:👉👉 Oracle数据库文章合集 👈👈 优