SQLzoo 习题记录07-More JOIN operations & Quiz

目录

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

JOIN Quiz 2


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
idtitleyrdirectorbudgetgross

 

actor
idname

 

casting
movieidactoridord

 

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

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
no main manifest attribute, in quiz-0.0.1-SNAPSHOT.jar 是一个报错信息,表示在quiz-0.0.1-SNAPSHOT.jar包的清单文件(MANIFEST.MF)中缺少了主清单属性。 解决这个问题的方法是在pom文件中添加以下配置: ``` <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> ``` 这个配置会在打包过程中自动生成并添加主清单属性,确保jar包能够正确运行。 同时,需要确保MANIFEST.MF文件夹和MANIFEST.MF文件位于项目的根目录下,才能够在本地使用java -jar命令运行jar包或在Docker容器中启动。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [no main manifest attribute, in app-1.0-SNAPSHOT.jar](https://blog.csdn.net/YonJarLuo/article/details/128530264)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [no main manifest attribute, in schoolspringboot-0.0.1-SNAPSHOT.jar](https://blog.csdn.net/weixin_52236586/article/details/131679246)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [start-0.0.1-SNAPSHOT.jar](https://download.csdn.net/download/qq_38807606/12268407)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值