JOIN quiz

game
id mdate stadium team1 team2
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
matchid teamid player gtime
1001 POL Robert Lewandowski 17
1001 GRE Dimitris Salpingidis 51
1002 RUS Alan Dzagoev 15
1001 RUS Roman Pavlyuchenko 82
...
eteam
id teamname coach
POL Poland Franciszek Smuda
RUS Russia Dick Advocaat
CZE Czech Republic Michal Bilek
GRE Greece Fernando Santos
...
1. You want to find the stadium where player 'Dimitris Salpingidis' scored. Select the JOIN condition to use:

 eteam JOIN game ON (id=team1)
 eteam JOIN game ON (id=team2)
 eteam JOIN goal ON (teamid=id)
 game  JOIN goal ON (id=matchid)
 game  JOIN goal ON (team1=teamid OR team2=teamid)
2. You JOIN the tables goal and eteam in an SQL statement. Indicate the list of column names that may be used in the SELECT line:

 gtime, mdate, stadium, matchid
 mdate, stadium, id
 matchid, teamid, player, gtime, id, teamname, coach
 matchid, teamid, player, gtime, mdate, stadium, team1
 stadium, team1, team2
3. Select the code which shows players, their team and the amount of goals they scored against Greece(GRE).

SELECT player, teamid, COUNT(*)
FROM game JOIN goal ON matchid = id
WHERE (team1 = "GRE" OR team2 = "GRE")
AND teamid != 'GRE'
GROUP BY player, teamid
SELECT player, teamid, COUNT(*)
FROM game JOIN goal ON matchid = id
WHERE (team1 = "GRE") AND teamid != 'GRE'
GROUP BY player, teamid
SELECT player, teamid, COUNT(*)
FROM game JOIN goal ON matchid = id
WHERE (team1 = "POL" OR team2 = "POL")
AND teamid != 'POL'
GROUP BY player, teamid
SELECT player, teamid, COUNT(*)
FROM game JOIN goal WITH matchid = id
WHERE (team1 = "GRE" OR team2 = "GRE")
AND teamid != 'GRE'
GROUP BY player, teamid
SELECT player, teamid
FROM game JOIN goal ON matchid = id
WHERE (team1 = "GRE" OR team2 = "GRE")
AND teamid != 'GRE'
GROUP BY player, teamid
4. Select the result that would be obtained from this code:

SELECT DISTINCT teamid, mdate
FROM goal JOIN game on (matchid=id)
WHERE mdate = '9 June 2012'
DEN 9 June 2012
GER 9 June 2012
DEN
GER
DEN 9 June 2012
DEN 9 June 2012
POL 9 June 2012
RUS 9 June 2012
GRE
CZE
POL
RUS
RUS 9 June 2012
GRE 9 June 2012
RUS 9 June 2012
CZE 9 June 2012
5. Select the code which would show the player and their team for those who have scored against Poland(POL) in National Stadium, Warsaw.

  SELECT DISTINCT player, teamid
FROM game JOIN goal ON matchid = id
WHERE stadium = 'National Stadium, Warsaw'
AND (team1 = 'GER' OR team2 = 'GER')
AND teamid != 'GER'
  SELECT DISTINCT player, teamid
FROM game JOIN goal ON matchid = id
WHERE stadium = 'National Stadium, Warsaw'
AND (team1 = 'POL' OR team2 = 'POL')
AND teamid != 'POL'
 SELECT DISTINCT player, teamid
FROM game JOIN goal ON matchid = id
WHERE stadium = 'National Stadium, Warsaw' AND teamid != 'POL'
 SELECT DISTINCT player, teamid
FROM game JOIN goal ON matchid = id
WHERE stadium = 'Stadion Miejski (Wroclaw)'
AND (team1 = 'POL' OR team2 = 'POL')
AND teamid != 'POL'
 SELECT DISTINCT stadium, mdate
FROM game JOIN goal ON matchid = id
WHERE stadium = 'National Stadium, Warsaw'
AND (team1 = 'POL' OR team2 = 'POL')
AND teamid != 'POL'
6. Select the code which shows the player, their team and the time they scored, for players who have played in Stadion Miejski (Wroclaw) but not against Italy(ITA).

SELECT DISTINCT player, teamid, gtime
FROM game JOIN goal ON matchid = id
WHERE stadium = 'National Stadium, Warsaw'
AND (( teamid = team2 AND team1 != 'ITA') OR ( teamid = team1 AND team2 != 'ITA'))
SELECT DISTINCT player, teamid, gtime
FROM game JOIN goal ON matchid = id
WHERE stadium = 'Stadion Miejski (Wroclaw)'
AND (( teamid = team2 AND team1 != 'ESP') OR ( teamid = team1 AND team2 != 'ESP'))
SELECT DISTINCT player, teamid, gtime
FROM game JOIN goal ON matchid = id
WHERE stadium = 'Stadion Miejski (Wroclaw)'
AND (( teamid = team2 AND team1 != 'ITA') OR ( teamid = team1 AND team2 != 'ITA'))
SELECT DISTINCT teamid, gtime
FROM game JOIN goal ON matchid = id
WHERE stadium = 'Stadion Miejski (Wroclaw)'
AND (( teamid = team2 AND team1 != 'ITA') OR ( teamid = team1 AND team2 != 'ITA'))
SELECT DISTINCT player, teamid, gtime
FROM game JOIN goal ON matchid = id
WHERE team1 != 'ITA' AND team2 !='ITA'
7. Select the result that would be obtained from this code:

SELECT teamname, COUNT(*)
FROM eteam JOIN goal ON teamid = id
GROUP BY teamname
HAVING COUNT(*) < 3
2
2
1
2
Netherlands 2
Poland 2
Republic of Ireland 1
Ukraine 2
Netherlands
Poland
Republic of Ireland
Ukraine
Poland 76
Republic of Ireland 1

mysql----JOIN Quiz的更多相关文章

  1. mysql join 查询图

    mysql join 查询,特别是对查两个表之间的差集,可以用table字段=null来做. 注意千万不是join on XX!=XX  ,这样出来的结果是错误的.

  2. MySQL JOIN原理

    先看一下实验的两张表: 表comments,总行数28856 表comments_for,总行数57,comments_id是有索引的,ID列为主键. 以上两张表是我们测试的基础,然后看一下索引,co ...

  3. MySQL Join算法与调优白皮书(三)

    Batched Key Access Join Index Nested-Loop Join虽好,但是通过辅助索引进行链接后需要回表,这里需要大量的随机I/O操作.若能优化随机I/O,那么就能极大的提 ...

  4. 图解mysql join

    原文:http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins 这个图文解释mysql join的各种技 ...

  5. 神奇的 SQL 之 联表细节 → MySQL JOIN 的执行过程(一)

    开心一刻 我:嗨,老板娘,有冰红茶没 老板娘:有 我:多少钱一瓶 老板娘:3块 我:给我来一瓶,给,3块 老板娘:来,你的冰红茶 我:玩呐,我要冰红茶,你给我个瓶盖干哈? 老板娘:这是再来一瓶,我家卖 ...

  6. MySQL JOIN原理(转)

    先看一下实验的两张表: 表comments,总行数28856 表comments_for,总行数57,comments_id是有索引的,ID列为主键. 以上两张表是我们测试的基础,然后看一下索引,co ...

  7. mysql JOIN关键字 语法

    mysql JOIN关键字 语法 作用:用于根据两个或多个表中的列之间的关系,从这些表中查询数据.大理石量具 说明:数据库中的表可通过键将彼此联系起来.主键(Primary Key)是一个列,在这个列 ...

  8. 神奇的 SQL 之 联表细节 → MySQL JOIN 的执行过程(二)

    开心一刻 一头母牛在吃草,突然一头公牛从远处狂奔而来说:“快跑啊!!楼主来了!” 母牛说:“楼主来了关我屁事啊?” 公牛急忙说:“楼主吹牛逼呀!” 母牛大惊,拔腿就跑,边跑边问:“你是公牛你怕什么啊? ...

  9. 神奇的 SQL 之 联表细节 → MySQL JOIN 的执行过程

    问题背景 对于 MySQL 的 JOIN,不知道大家有没有去想过他的执行流程,亦或有没有怀疑过自己的理解(自信满满的自我认为!):如果大家不知道怎么检验,可以试着回答如下的问题 驱动表的选择 MySQ ...

  10. Python MySQL Join

    章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...

随机推荐

  1. Chapter 4 Invitations——9

    I didn't want to get into the safety hazards that dancing presented, so I quickly made new plans. 我不 ...

  2. go builtin包

    Go builtin包提供了go预先声明的函数.变量等的文档.这些函数变量等的实现其实并不是在builtin包里,只是为了方便文档组织. 这些内置的变量.函数.类型无需引入包即可使用. 默认提供的有: ...

  3. Go pprof性能监控

    Go net/http/pprof包提供了一个在WEB项目中使用的性能监控的工具, 使用时只需要引用包: _"net/http/pprof" 然后就可以在浏览器中访问地址: htt ...

  4. 痞子衡嵌入式:备受开源社区推崇的分布式版本控制工具(Git)

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是分布式版本控制工具Git. 1.为什么需要版本控制系统? 单人软件项目开发过程,往往很多功能都是逐步增加的,在代码开发过程中,有的时候功 ...

  5. paramiko之ssh登录,执行cmd,下载文件

    一.paramiko远程登录及执行命令 1.1:exec_command(cmd)远程执行命令 client = paramiko.SSHClient() client.set_missing_hos ...

  6. Dapper批量更新

    本次示例项目使用Dappe1.50.5和Dapper.Contrib1.50.5 数据库执行的脚本检测工具是SQL Server Prifiler 1.使用Where In 实现批量更新 1.1代码如 ...

  7. SpringBoot解决ajax跨域问题

    一.第一种方式: 1.编写一个支持跨域请求的 Configuration import org.springframework.context.annotation.Configuration; im ...

  8. 理解 Python 中的可变参数 *args 和 **kwargs:

    默认参数:  Python是支持可变参数的,最简单的方法莫过于使用默认参数,例如: def getSum(x,y=5): print "x:", x print "y:& ...

  9. 买or不买?如何测试博彩公司赔率是否合理?

    世界杯期间,烧烤店.酒吧都热闹起来了,柔柔我的朋友圈也热闹起来了,有酱紫的: 还有酱紫的: 然后还有酱紫的: 酱紫的: 当然天台也是一如既然的热闹: 似乎人人都在输钱,那真正的赢家在哪里呢?博彩业的真 ...

  10. Java学习笔记之——枚举类

    枚举可以限定类的值只是有限个,例如:星期,只有星期一到星期天 语法案例: