mysql begin operations_MySQL入门(七):More JOIN operations

Sqlzoo习题练习:More JOIN operations

下面会涉及到更多连接的概念。数据库由三个表组成:movie , actor 和 casting以及三个表之间的关系。

下面为More JOIN 习题内容:

--#1/*List the films where the yr is 1962 [Show id, title]*/

SELECT id, title

FROM movie

WHERE yr=1962;

--#2/*Give year of '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.*/

SELECT id,title,yr

FROM movie

WHERE title LIKE 'Star Trek%';

--#4/*What id number does the actor 'Glenn Close' have?*/

SELECT id FROM actor

WHERE name = 'Glenn Close';

--#5/*What is the id of the film 'Casablanca'*/

SELECT id

FROM movie

WHERE title = 'Casablanca';

--#6/*Obtain the cast list for 'Casablanca'.what is a cast list?The cast list is the names of the actors who were in the movie.Use movieid=11768, (or whatever value you got from the previous question)*/

SELECT actor.name

FROM actor JOIN casting ON (actor.id=casting.actorid)

WHERE casting.movieid = 11768;

--#7/*Obtain the cast list for the film 'Alien'*/

SELECT actor.name

FROM actor JOIN casting

ON (actor.id=casting.actorid)

JOIN movie

ON (movie.id = casting.movieid)

WHERE movie.title = 'Alien' ;

--#8/*List the films in which 'Harrison Ford' has appeared*/

SELECT movie.title

FROM actor JOIN casting

ON (actor.id=casting.actorid)

JOIN movie

ON (movie.id = casting.movieid)

WHERE actor.name = 'Harrison Ford';

--#9/*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]*/

SELECT movie.title

FROM actor JOIN casting

ON (actor.id=casting.actorid)

JOIN movie

ON (movie.id = casting.movieid)

WHERE actor.name = 'Harrison Ford' AND casting.ord != 1;

--#10/*List the films together with the leading star for all 1962 films.*/

SELECT movie.title,actor.name

FROM actor JOIN casting

ON (actor.id=casting.actorid)

JOIN movie

ON (movie.id = casting.movieid)

WHERE movie.yr = 1962

AND casting.ord = 1;

知识点:MAX() 函数

MAX 函数返回一列中的最大值。NULL 值不包括在计算中。

MAX() 语法

SELECT MAX(column_name) FROM table_name

--#11

/*

Which were the busiest years for 'John Travolta', show the year and the number of movies he made each year for any year in which he made more than 2 movies.

*/

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)=(SELECT MAX(c) FROM

(SELECT yr,COUNT(title) AS c FROM

movie JOIN casting ON movie.id=movieid

JOIN actor ON actorid=actor.id

where name='John Travolta'

GROUP BY yr) AS t

);

--#12

/*

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

Did you get "Little Miss Marker twice"?

Julie Andrews starred in the 1980 remake of Little Miss Marker and not the original(1934).

Title is not a unique field, create a table of IDs in your subquery

*/

SELECT DISTINCT m.title,a.name

FROM (SELECT movie.*

FROM actor JOIN casting

ON (actor.id=casting.actorid)

JOIN movie

ON (movie.id = casting.movieid)

WHERE actor.name = 'Julie Andrews') AS m

JOIN (SELECT actor.*,casting.movieid AS movieid

FROM actor JOIN casting

ON (actor.id=casting.actorid)

WHERE casting.ord = 1) AS a

ON m.id = a.movieid

ORDER BY m.title;

--#13

/*

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

*/

SELECT actor.name

FROM actor

JOIN casting

on (actor.id = casting.actorid)

WHERE casting.ord = 1

GROUP BY actor.name

HAVING COUNT(*) >= 30;

--#14

/*

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

*/

SELECT movie.title, COUNT(actorid) AS cast_actors

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 cast_actors DESC,movie.title;

--#15

/*

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

*/

SELECT a.name

FROM (SELECT movie.*

FROM movie

JOIN casting

ON casting.movieid = movie.id

JOIN actor

ON actor.id = casting.actorid

WHERE actor.name = 'Art Garfunkel') AS m

JOIN (SELECT actor.*, casting.movieid

FROM actor

JOIN casting

ON casting.actorid = actor.id

WHERE actor.name != 'Art Garfunkel') as a

ON m.id = a.movieid;

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

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

相关文章

win10安装mysql5.7.15_win10上如何安装mysql5.7.16(解压缩版)

注:本文涉及的是解压缩版的安装安装教程下载mysql解压缩下载的文件修改ini文件(在解压缩后的mysql文件夹中)实际上修改的是my-default.ini文件在文件中添加如下路径和地址其中的data文件夹是没有的必须自己创建。# These are commonly set, remove the # and set as…

mysql error log清理_手动删除mysql日志/var/log/mysql/error.log导致的mysql无法启动

问题环境ubuntu-mate for raspberrymysql默认配置问题起源最近在搞fail2ban这东西,顺便翻了翻各种日志,然后看见mysql的日志有点多就想清理一下,于是直接sudo rm -r /var/log/mysql了一下,结果重启之后发现mysql就不跑了。。。手动…

mysql开启权限控制_mysql开启远程访问及相关权限控制

开启mysql远程访问:授予用户user 密码 passwd 所有权限 所有主机IP可访问授权语句:Grant on 表名[(列名)] to 用户 With grant option或 GRANT ON FROM GRANT ALL PRIVILEGES ON *.* TO user% IDENTIFIED BY passwd WITH GRANT OPTION;ALL PRIVILEGES表示…

mysql awr 上海用户组_mysql awr v1.0.3修正说明以及发布

本版本计划修正或者包含如下内容:1、innodb buffer_pool只是分配的vm大小,实际并不一定真正使用这么多,还可能会有内存泄露,故调整从innodb_buffer_pool_stats获取实际值并显示,同时获取mysqld进程实际占用的物理内存&…

mysql如何备份一个表单_Mysql亿级数据大表单表备份

上一篇Mysql已有亿级数据大表按时间分区,介绍了亿级数据大表如何按时间分区,也留下了一个问题:备份亿级数据大表要耗时多久。本篇将就如何备份亿级数据大表展开讨论。注意:我这里所说的备份指的是数据从一张表拷贝到另外一张表&am…

mysql mos login_MySQL 中常用的函数

一、DATE_FORMAT()需求:按照日期月份统计数据,但数据库存储的格式是 2020-10-01 10:20:45 ,因此需要格式化日期语法:DATE_FORMAT(date,format)第一个参数:指定的日期,第二个参数:需要获取的格式…

mysql用户信息备份还原_mysql迁移之新建用户、备份还原数据库

事例➜ 1 mysql -uzixie -pzixie game < /temp/zixie_back.sqlmysql: [Warning] Using a password on the command line interface can be insecure.➜ 1 mysql -uzixie -p"zixie"mysql: [Warning] Using a password on the command line interface can be insecu…

centos radius mysql_FreeRadius2 MySQL配置

FreeRadius2可以和MySQL进行集成&#xff0c;集成的内容包括创建符合要求的数据库和表结构&#xff0c;为MySQL进行的相关配置&#xff0c;基于数据库安装Web管理程序(如daloradius,ARA等)&#xff0c;大部分内容可以参见0. 环境FreeRadius2 / MySQL 5 /CentOS 5.5(VirtualBox)…

需求调研的方法及过程_培训需求调研方法

课程设计与开发是每一位职业培训师都必须会的技能&#xff0c;今天我们就来分享一下如何开发课程。第一节课&#xff0c;让我们先从培训需求调研开始。培训需求调研方法有很多&#xff0c;从个体层次分为&#xff1a;问卷法、观察法、访谈法&#xff1b;从组织层次分为&#xf…

java报错空指针异常_java – 空指针异常错误,没有明显的代码错误

我在这里有一个错误,我不知道它来自哪里.我在初学者的java课程是高中,所以我在这里还没有太多的经验.我有3个相互合并的程序.我有一个卡片类,可以创建一张扑克牌//********************************************************************// Card.java Author: Lewis and Loftus…

mysql表的设计几种方式_支持多种登录方式的数据表设计 | 六阿哥博客

一个带有用户系统的应用最基本登录方式是站内账号登录&#xff0c;但这种方式往往不能满足我们的需求。现在的应用基本都有站内账号、email、手机和一堆第三方登录&#xff0c;那么如果需要支持这么多种登录方式&#xff0c;或者还有银行卡登录、身份证登录等等更多的登录方式&…

将Go语言开发的Web程序部署到K8S

搭建K8S基础环境 如果已经有K8S环境的同学可以跳过&#xff0c;如果没有&#xff0c;推荐你看看我的《Ubuntu22加Minikue搭建K8S环境》&#xff0c;课程目录如下&#xff1a; Ubuntu22安装Vscode 下载&#xff1a;https://code.visualstudio.com/Download 安装命令&#…

python 扫描仪_基于Opencv和Python的多选扫描仪

首先&#xff0c;我检测到图像右侧的20个黑框&#xff0c;然后将x和宽度添加到列表中&#xff1a;image cv2.imread(args["image"])gray cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)(_, thresh) cv2.threshold(gray, 220, 255,cv2.THRESH_BINARY)kernel cv2.getStr…

mysql dmz_MySQL 中LIMIT的使用详解

MySQL的Limit子句Limit子句可以被用于强制 SELECT 语句返回指定的记录数。Limit接受一个或两个数字参数。参数必须是一个整数常量。如果给定两个参数&#xff0c;第一个参数指定第一个返回记录行的偏移量&#xff0c;第二个参数指定返回记录行的最大数目。//初始记录行的偏移量…

python编程入门到实践笔记习题_Python编程从入门到实践笔记——列表简介

python编程从入门到实践笔记——列表简介#codingutf-8#列表——我的理解等于c语言和java中的数组bicycles ["trek","cannondale","readline","specialized"]print(bicycles)#列表索引从0开始print(bicycles[0].title())#访问列表元素…

informatica mysql odbc_Informatica 配置mysql community odbc连接

Informatica linux 版本内置的DataDirect 驱动支持各种数据库例如oracle、sybase、postgreSQL、Greenplum、mysql等等但是mysql 只支持企业版本&#xff0c;如果我们使用的是community 社区版本便不能使用自带的DataDirect方式了&#xff0c;那我们就需要手动配置其他odbc连接。…

mysql分表 动态扩容_数据库hash分表后的扩容方案

postgres的hash分表不停机扩容方案原来我们hash分表之后&#xff0c;数据扩容采用的是rehash&#xff0c;这样迁移全部的数据&#xff0c;比较麻烦。本次扩容利用hash环原理&#xff0c;并在此基础上做一些适应性的改动。首先假定哈希环的范围为0-1023&#xff0c;总共1024的数…

php mysql长连接聊天室_PHP之探索MySQL 长连接、连接池

PHP连接MysqL的方式&#xff0c;用的多的是MysqL扩展、MysqLi扩展、pdo_MysqL扩展,是官方提供的。PHP的运行机制是页面执行完会释放所有该PHP进程中的所有资源的&#xff0c;如果有多个并发访问本地的测试页面 http://127.0.0.1/1.php 根据PHP跟web服务器的不同&#xff0c;会开…

python 读取地震道头数据_python地震数据可视化详解

本文实例为大家分享了python地震数据可视化的具体代码&#xff0c;供大家参考&#xff0c;具体内容如下准备工作&#xff1a;在windows10下安装python3.7&#xff0c;下载参考源码到本地。1. demo绘图测试demo绘图指令cmd> python seisplot.py --demo问题1)缺少依赖包File &…

在MySQL查询山东省男生信息_MySQL-查询

来一波英语单词解释(意思)create 创建show 显示database 数据库use 使用select 选择table 表from 来自…distinct 消除重复行as 同样地(用于其别名)where 范围like 模糊查询rlike 正则查询In 范围查询not in 不非连续的范围之内between ... and …表示…