SQLZOO练习5–join(表的连接)

game表:

idmdatestadiumteam1team2 1001 8 June 2012 National Stadium, Warsaw POL GRE 1002 8 June 2012 Stadion Miejski (Wroclaw) RUS CZE 1003 12 June 2012 Stadion Miejski (Wroclaw) GRE CZE 1004 12 June 2012 National Stadium, Warsaw POL RUS ……

goal表:

matchidteamidplayergtime 1001 POL Robert Lewandowski 17 1001 GRE Dimitris Salpingidis 51 1002 RUS Alan Dzagoev 15 1002 RUS Roman Pavlyuchenko 82 ……

team表:

idteamnamecoach POL Poland Franciszek Smuda RUS Russia Dick Advocaat CZE Czech Republic Michal Bilek GRE Greece Fernando Santos ……

1、获取德国的比赛id和参赛人员。

The first example shows the goal scored by a player with the last name ‘Bender’. The * says to list all the columns in the table – a shorter way of saying matchid, teamid, player, gtime

Modify it to show the matchid and player name for all goals scored by Germany. To identify German players, check for: teamid = 'GER'

2、Show id, stadium, team1, team2 for just game 1012

From the previous query you can see that Lars Bender’s scored a goal in game 1012. Now we want to know what teams were playing in that match.

Notice in the that the column matchid in the goal table corresponds to the id column in the game table. We can look up information about game 1012 by finding that row in the game table.

Show id, stadium, team1, team2 for just game 1012

You can combine the two steps into a single query with a JOIN.

SELECT *
  FROM game JOIN goal ON (id=matchid)

The FROM clause says to merge data from the goal table with that from the game table. The ON says how to figure out which rows in game go with which rows in goal – the matchid from goal must match id from game. (If we wanted to be more clear/specific we could say
ON (game.id=goal.matchid)

The code below shows the player (from the goal) and stadium name (from the game table) for every goal scored.

Modify it to show the player, teamid, stadium and mdate for every German goal.

4、Show the team1, team2 and player for every goal scored by a player called Mario player LIKE 'Mario%'

Use the same JOIN as in the previous question.

5、Show player , teamid , coach , gtime for all goals scored in the first 10 minutes gtime<=10< code><!--=10<-->

The table eteam gives details of every national team including the coach. You can JOIN goal to eteam using the phrase goal JOIN eteam on teamid=id

6、List the dates of the matches and the name of the team in which ‘Fernando Santos’ was the team1 coach.

To JOIN game with eteam you could use either

game JOIN eteam ON (team1=eteam.id) or game JOIN eteam ON (team2=eteam.id)

Notice that because id is a column name in both game and eteam you must specify eteam.id instead of just id

7、List the player for every goal scored in a game where the stadium was ‘National Stadium, Warsaw’

8、 The example query shows all goals scored in the Germany-Greece quarterfinal.

Instead show the name of all players who scored a goal against Germany.

HINT

Original: https://www.cnblogs.com/ruoli-121288/p/16278980.html
Author: 徐若离
Title: SQLZOO练习5–join(表的连接)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/621700/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 用Python自动实现图表可视化操作,提高工作效率,又能有更多的时间摸鱼了~

    在数据分析过程中,一般提取数据库里面的数据时候,拿着表格数据反复思索,希望能够根据自己所想立马生成一张数据可视化的图表来更直观的呈现数据。 但想要进行数据可视化的时候,往往需要调用…

    数据库 2023年6月14日
    059
  • 数据结构入门之单链表代码实现(java)

    1:单链表是: 单链表是一种链式存取的 数据结构 用一组地址任意的 存储单元 存放线性表中的数据元素。 链表中的数据是以结点来表示的,每个结点的构成:元素 ( 数据元素 的映象) …

    数据库 2023年6月6日
    0109
  • JMeter接口自动化发包与示例

    JMeter接口自动化发包与示例 近期需要完成对于接口的测试,于是了解并简单做了个测试示例,看了看这款江湖上声名远播的强大的软件-Jmeter靠不靠谱。官网:https://jme…

    数据库 2023年6月6日
    063
  • 解决Tomcat部署工件中无子模块的工件

    本文是在尝试了刷新Maven项目、clean了Maven缓存并且重启IDEA之后任然无法在Tomcat中找到子模块对应的工件,这时就要试着模仿着自己创建一个模块父类的pom.xml…

    数据库 2023年6月16日
    086
  • 线程本地存储 ThreadLocal

    线程本地存储提供了线程内存储变量的能力,这些变量是线程私有的。 线程本地存储一般用在跨类、跨方法的传递一些值。 线程本地存储也是解决特定场景下线程安全问题的思路之一(每个线程都访问…

    数据库 2023年6月11日
    094
  • MySQL 数据库备份脚本

    MySQL 数据库备份脚本 #!/bin/bash 数据库连接信息 DB_HOST="127.0.0.1" DB_PORT="3306" D…

    数据库 2023年5月24日
    090
  • MySQL完整版详解

    一、数据库的操作 1.创建数据库 若在可视化软件上创建数据库,参考如下图 如果要创建的数据库不存在,则创建成功 create database if not exists west…

    数据库 2023年6月16日
    066
  • [mybatis]快速搭建一个mybatis程序,实现对数据的增删改查

    MyBatis 是一款优秀的持久层框架,它支持自定义 SQL、存储过程以及高级映射。 MyBatis 免除了几乎所有的 JDBC 代码以及设置参数和获取结果集的工作。 MyBati…

    数据库 2023年5月24日
    087
  • mysql绿色版在windows系统中的启动

    Original: https://www.cnblogs.com/java265/p/15597871.htmlAuthor: java265Title: mysql绿色版在wi…

    数据库 2023年5月24日
    089
  • Mysql8+数据库安装和使用

    一、Mysql的版本选择 Mysql目前分文社区版和企业版,社区版在技术方面会加入许多新的未经严格测试的特性,而企业版经过严格测试认证,更加稳定、安全、可靠,性能也比社区版好。社区…

    数据库 2023年6月14日
    081
  • Vscode配置安装Golang开发环境

    1.下载安装Golanghttps://golang.google.cn/dl/ 一路下一步即可 2.下载安装Vscodehttps://visualstudio.microsof…

    数据库 2023年6月16日
    0101
  • SQL Server内置的HTAP技术

    SQL Server内置的HTAP技术 目录 背景 SQL Server在OLAP上的发展 SQL Server的初代HTAP SQL Server逐渐增强的HTAP SQL Se…

    数据库 2023年6月9日
    0131
  • Mysql数据库基础_复习思维导图

    Mysql复习的一个小总结,用xmind写的。(字数没有都不给我发博客😹) 下面是一些备注 子查询 MySQL子查询称为内部查询,而包含子查询的查询称为外部查询。 子查询可以在使用…

    数据库 2023年5月24日
    074
  • Linux快速安装流量监控工具(实用版)

    前言: Linux流量监控工具,在此我推荐两种分别为: 1、nload(推荐)因为个人看着舒服点😂 2、iftop 以上两种任选其一即可,在此对两种都有介绍和安装教程,我写了,大家…

    数据库 2023年6月16日
    086
  • Java 可重入锁的那些事(一)

    本文主要包含的内容:可重入锁(ReedtrantLock)、公平锁、非公平锁、可重入性、同步队列、CAS等概念的理解 显式锁🔒 上一篇文章提到的synchronized关键字为隐式…

    数据库 2023年6月6日
    0122
  • SQL Server中STATISTICS IO物理读和逻辑读的误区

    SQL Server中STATISTICS IO物理读和逻辑读的误区 大家知道,SQL Server中可以利用下面命令查看某个语句读写IO的情况 SET STATISTICS IO…

    数据库 2023年6月9日
    078
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球