目录

More JOIN operations

  1. 1962 movies
  2. When was Citizen Kane released?
  3. Star Trek movies
  4. id for actor Glenn Close
  5. id for Casablanca
  6. Cast list for Casablanca
  7. Alien cast list
  8. Harrison Ford movies
  9. Harrison Ford as a supporting actor
  10. Lead actors in 1962 movies
  11. Busy years for Rock Hudson
  12. Lead actor in Julie Andrews movies

13-15. Actors with 15 leadign roles

  • 13.
  • 14.
  • 15.

JOIN Quiz 2

  • 1. Select the statement which lists the unfortunate directors of the movies which have caused financial loses (gross < budget)
  • 2. Select the correct example of JOINing three tables
  • 3. Select the statement that shows the list of actors called 'John' by order of number of movies in which they acted
  • 4. Select the result that would be obtained from the following code:
  • 5. Select the statement that lists all the actors that starred in movies directed by Ridley Scott who has id 351
  • 6. There are two sensible ways to connect movie and actor. They are:
  • 7. Select the result that would be obtained from the following code:

More JOIN operations

网址:More JOIN operations - SQLZOO

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

movie
id title yr director budget gross
actor
id name
casting
movieid actorid ord

1962 movies

1.

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

  • SELECT id, title FROM movie
  • WHERE yr=1962;

When was Citizen Kane released?

2.

Give year of 'Citizen Kane'.

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

Star Trek movies

3.

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.

  • SELECT id,title,yr FROM movie
  • WHERE title LIKE '%Star Trek%'
  • ORDER BY yr;

id for actor Glenn Close

4.

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

  • SELECT id FROM actor
  • Where name='Glenn Close';

id for Casablanca

5.

What is the id of the film 'Casablanca'

  • SELECT id FROM movie
  • WHERE title = 'Casablanca';

Cast list for 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 name FROM actor A
  • LEFT JOIN Casting C ON a.id=c.actorid
  • LEFT JOIN movie M ON m.id = c.movieid
  • WHERE movieid=27;

Alien cast list

7.

Obtain the cast list for the film 'Alien'

  • SELECT name FROM actor A
  • LEFT JOIN Casting C ON a.id=c.actorid
  • LEFT JOIN movie M ON m.id = c.movieid
  • WHERE title ='Alien';

Harrison Ford movies

8.

List the films in which 'Harrison Ford' has appeared

  • SELECT title FROM actor A
  • LEFT JOIN Casting C ON a.id=c.actorid
  • LEFT JOIN movie M ON m.id = c.movieid
  • WHERE name = 'Harrison Ford';

Harrison Ford as a supporting actor

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 title FROM actor A
  • LEFT JOIN Casting C ON a.id=c.actorid
  • LEFT JOIN movie M ON m.id = c.movieid
  • WHERE name = 'Harrison Ford'
  • And ord <> 1;

Lead actors in 1962 movies

10.

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

  • SELECT title,name FROM actor A
  • LEFT JOIN Casting C ON a.id=c.actorid
  • LEFT JOIN movie M ON m.id = c.movieid
  • WHERE yr = 1962
  • AND ord = 1;

Harder Questions


Busy years for Rock Hudson

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.

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

Lead actor in Julie Andrews movies

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(不知道为什么我没有遇到提示的问题,不过这题的代码是真的长,希望有人能指导一下更加简化的写法呢~)

P.S.橙色部分是重复字段,关联三张表用的

  • Select title,name FROM actor A
  • LEFT JOIN Casting C ON a.id=c.actorid
  • LEFT JOIN movie M ON m.id = c.movieid
  • Where title IN(SELECT title FROM actor A
  • LEFT JOIN Casting C ON a.id=c.actorid
  • LEFT JOIN movie M ON m.id = c.movieid
  • Where name = 'Julie Andrews')
  • And ord = 1;

Actors with 15 leading roles

13.

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

  • SELECT name FROM actor a
  • LEFT JOIN casting c ON a.id = c.actorid
  • WHERE ord=1
  • GROUP BY name
  • HAVING COUNT(*) >=15
  • ORDER BY name;

14.

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

  • SELECT title,COUNT(DISTINCT actorid) FROM movie M
  • LEFT JOIN casting C ON m.id = c.movieid
  • WHERE yr = 1978
  • GROUP BY title
  • ORDER BY COUNT(DISTINCT actorid) desc,title;

15.

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

P.S.橙色部分是重复字段,关联actor 和 casting表用的。

  • SELECT DISTINCT name FROM actor A
  • LEFT JOIN casting C ON a.id=c.actorid
  • Where name <> 'Art Garfunkel'
  • And movieid IN(SELECT movieid From actor A
  • LEFT JOIN casting C ON a.id=c.actorid
  • WHERE name = 'Art Garfunkel')
  • ORDER BY name;

JOIN Quiz 2

网址:JOIN Quiz 2 - SQLZOO

1. Select the statement which lists the unfortunate directors of the movies which have caused financial loses (gross < budget)

  • SELECT name FROM actor
  • INNER JOIN movie ON actor.id = director
  • WHERE gross < budget;

2. Select the correct example of JOINing three tables

  • SELECT * FROM actor
  • JOIN casting ON actor.id = actorid
  • JOIN movie ON movie.id = movieid;

3. Select the statement that shows the list of actors called 'John' by order of number of movies in which they acted

  • SELECT name, COUNT(movieid) FROM casting
  • JOIN actor ON actorid=actor.id
  • WHERE name LIKE 'John %'
  • GROUP BY name
  • ORDER BY 2 DESC;

4. Select the result that would be obtained from the following code:

  •  SELECT title FROM movie JOIN casting ON (movieid=movie.id)JOIN actor   ON (actorid=actor.id)WHERE name='Paul Hogan' AND ord = 1

Table-B

"Crocodile" Dundee Crocodile Dundee in Los Angeles Flipper Lightning Jack

5. Select the statement that lists all the actors that starred in movies directed by Ridley Scott who has id 351

  • SELECT name FROM movie
  • JOIN casting ON movie.id = movieid
  • JOIN actor ON actor.id = actorid
  • WHERE ord = 1
  • AND director = 351;

6. There are two sensible ways to connect movie and actor. They are:

  • link the director column in movies with the primary key in actor
  • connect the primary keys of movie and actor via the casting table

7. Select the result that would be obtained from the following code:

  •  SELECT title, yr FROM movie, casting, actor WHERE name='Robert De Niro' AND movieid=movie.id AND actorid=actor.id AND ord = 3

Table-B

A Bronx Tale 1993 Bang the Drum Slowly 1973 Limitless 2011

SQLzoo 习题记录07-More JOIN operations Quiz相关推荐

  1. sqlzoo第七关More JOIN operations

    第七关 More JOIN operations 电影数据库 表1 电影表(movie) id(编号) title(电影名) yr(年份) director(导演) budget(制作费) gross ...

  2. SQLzoo 习题记录06-The JOIN operation Quiz

    目录 The JOIN operation 1. 2. 3. 4. 5. 6. 7. More difficult questions 8. 9. 10.

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

    Sqlzoo习题练习:More JOIN operations 下面会涉及到更多连接的概念.数据库由三个表组成:movie , actor 和 casting以及三个表之间的关系. 下面为More J ...

  4. 软件项目管理,第二讲,习题记录

    文章目录 1.Scrum题目 2. 习题记录 第二讲,讲义总结链接 https://blog.csdn.net/weixin_42245375/article/details/104662939 1. ...

  5. SQLZOOL练习题答案和解析 第7关 More JOIN operations

    第7关 More JOIN operations - SQLZOO 练习 join -- 1.List the films where the yr is 1962 [Show id, title] ...

  6. Python习题记录

    纯当复习练习用,发出来供大家参考.华中农业大学习题记录,有些题可能有其他的简洁做法,错误欢迎指正. 目录 输入一个星期数字,返回对应星期的名称缩写前2个字母. 5.1猴子吃桃问题 5.2韩信点兵 5. ...

  7. SQLZOO习题详解(06)——The JOIN operation

    练习地址 1.Modify it to show the matchid and player name for all goals scored by Germany. To identify Ge ...

  8. sqlzoo - 7 More JOIN operations

    目录 6. ? Cast list for Casablanca 7. - Alien cast list 8. - Harrison Ford movies 9. Harrison Ford as ...

  9. 2021-11-25 统计学-基于R(第四版)第八章课后习题记录及总结

    先声明,本博客为个人作业不一定为标准答案,仅供参考 8.1 题目如下 (1) H₀:α₁=α₂=α₃=α₄=0 H₁:α₁,α₂,α₃,α₄至少有一个不等于0 > example8_1<- ...

最新文章

  1. AI一分钟 | 马斯克证实:特斯拉私有化的幕后推手是沙特主权基金;DeepMind的AI可以检测出超过50种眼疾...
  2. 微软云Azure创建一个web app
  3. Java编译分类:前端编译和后端编译
  4. cisco *** 案例2
  5. C语言进阶--Day2
  6. 数据库设计(三)概念数据模型
  7. linux cp后文件变大,使用 rsync 复制大文件的一些误解 | Linux 中国
  8. android java 时间格式化_(Java / Android)计算两个日期之间的日期,并以特定格式显示结果...
  9. plsql提示列快捷键_PLsql快捷键
  10. java反显是什么_卡西欧反显是什么意思
  11. python使用itchat获取微信好友列表
  12. OD常用快捷键(对比SoftICE)
  13. PADS 去除走线折角处提示和过孔提示
  14. html编辑器的回车换行问题解决方案
  15. vim 编辑器常用操作
  16. 下载到的电子书格式是Mobi,这种格式能否在手机上打开?
  17. 【LeetCode】【VSCode】在VSCode中使用插件刷题
  18. Python学习笔记--10.Django框架快速入门之后台管理admin(书籍管理系统)
  19. 微信的那个老外产品经理又写了一篇《中国移动应用设计趋势》
  20. laraverl框架房源管理

热门文章

  1. 微信小程序canvas大小、定位适配
  2. 苏仪数据分析软件 更新 Analys1.2.2 2007/12/27
  3. java 计数器怎么定义_4.7 JAVA计数器
  4. 安装绿色版MongoDB
  5. 产品经理之流程图表达业务逻辑(非原创)
  6. Principle for Mac(交互原型设计工具)
  7. 四轮 控制算法 麦轮_基于麦克纳姆轮的全向移动自主机器人
  8. 使用NI-DAQmx获取设备名及物理通路名
  9. 前端meta标签内容定义及使用说明,meta详细说明,meta标签使用
  10. python-PyCharm导入numpy库