学习原链接:Old JOIN Tutorial

The Table Tennis Olympics Database


The table ttms shows the Olympic medal winners for Table Tennis (Men’s Singles). The country of each winner is given by a three letter code. To get the actual country name you must JOIN this table to the country table.
(译文)表ttms显示了奥运会乒乓球(男子单打)奖牌获得者。每个获胜者的国家由三个字母组成的 id 表示。要获得实际的国家名称,必须将此表联接到国家表。
The two tables country and ttms are ONE TO MANY. One country has many winners, each winner has only one country.
(译文)country表和ttms表是一对多的关系,一个国家有多个获奖者,每一个获奖者只有一个国家。

How to do joins

The phrase FROM ttms JOIN country ON ttms.country=country.id represents the join of the tables ttms and country. This JOIN has one row for every medal winner. In addition to the ttms fields (games, color, who and country) it includes the details of the corresponding country (id, name ).
(译文)短语FROM ttms JOIN country ON ttms.contry=country。id表示表ttms和country的连接。此JOIN为每个奖牌获得者为一行。除了ttms字段(游戏、颜色、姓名和国家)之外,它还包括相应国家的详细信息(id、名称)。

1.Show the athlete (who) and the country name for medal winners in 2000.

SELECT who,name
FROM ttms JOIN country ON country = id
WHERE games = 2000

2.Show the who and the color of the medal for the medal winners from ‘Sweden’.

SELECT who,color
FROM ttms JOIN country ON country = id
WHERE name = 'Sweden'

3.Show the years in which ‘China’ won a ‘gold’ medal.

SELECT games
FROM  ttms JOIN country ON country = id
WHERE name = 'China' AND color = 'gold'

Women’s Singles Table Tennis Olympics Database

The Summer Olympic games are held every four years in a different city. The table games shows which city the games were held in. The Women’s Single’s winners are in the table ttws.
(译文)夏季奥运会每四年在不同的城市举行一次,games表显示举行比赛的城市,女子单打获胜者在ttws表。

4.Show who won medals in the ‘Barcelona’ games.

SELECT who
FROM ttws JOIN games ON games = yr
WHERE city = 'Barcelona'

5.Show which city ‘Jing Chen’ won medals. Show the city and the medal color.

SELECT city,color
FROM ttws JOIN games ON games = yr
WHERE who = 'Jing Chen'

6.Show who won the gold medal and the city.

SELECT who ,city
FROM ttws JOIN games ON games = yr
WHERE color = 'gold '

Table Tennis Mens Doubles

The Table Tennis Mens Double teams are stored in the table team.
Each team has an arbitrary number that is referenced from the table ttmd.
(译文)这乒乓球男子双打队名team保存在team表,每个队的id对应表ttmd里的team字段

7.Show the games and color of the medal won by the team that includes ‘Yan Sen’.

SELECT games,color
FROM ttmd JOIN team ON team = id
WHERE name = 'Yan Sen'

8.Show the ‘gold’ medal winners in 2004.

SELECT name
FROM ttmd JOIN team ON team = id
WHERE games = 2004 AND color = 'gold'

9.Show the name of each medal winner country ‘FRA’.

SELECT name
FROM ttmd JOIN team ON team = id
WHERE country = 'FRA'

总结:从学习效果来看,这节课适合放在 join 的第一节课学习,比较容易,对初学者友好,这篇学完后再学新的JOIN就学习效果循序渐进。

SQL ZOO 练习 —— Old JOIN Tutorial相关推荐

  1. SQL ZOO 练习 —— The JOIN operation

    The JOIN operation 学习原链接:The_JOIN_operation 1.The first example shows the goal scored by a player wi ...

  2. sql语句中left join和inner join中的on与where的区别分析

    原文:sql语句中left join和inner join中的on与where的区别分析 关于SQL SERVER的表联接查询INNER JOIN .LEFT JOIN和RIGHT JOIN,经常会用 ...

  3. Linq To Sql中实现Left Join与Inner Join使用Linq语法与lambda表达式

    当前有两个表,sgroup与sgroupuser,两者通过gKey关联,而sgroup表记录的是组,而sgroupuser记录是组中的用户,因此在sgroupuser中不一定有数据.需要使用Left ...

  4. Spark SQL中出现 CROSS JOIN 问题解决

    Spark SQL中出现 CROSS JOIN 问题解决 参考文章: (1)Spark SQL中出现 CROSS JOIN 问题解决 (2)https://www.cnblogs.com/yjd_hy ...

  5. LINQ to SQL语句(4)之Join

    LINQ to SQL语句(4)之Join Join操作符 适用场景:在我们表关系中有一对一关系,一对多关系, 多对多关系等.对各个表之间的关系,就用这些实现对多个表的操作. 说明:在Join操作中, ...

  6. mysql sql left right inner join区别及效率比较

    一.Join语法概述 join 用于多表中字段之间的联系,语法如下: ... FROM table1 INNER|LEFT|RIGHT JOIN table2 ON conditiona table1 ...

  7. SQL 经典回顾:JOIN 表连接操作不完全指南

    也许最强大的SQL功能是JOIN操作.这让所有非关系数据库羡慕不已,因为当你想"合并"两个数据集时,这个概念是如此简单,并且又普遍适用. 简单地说,连接两个表,就是将一个表中的每一 ...

  8. SQL语句中LEFT JOIN、JOIN、INNER JOIN、RIGHT JOIN的区别?

    w3school的一套sql教程: http://www.w3school.com.cn/sql/index.asp left join :左连接,返回左表中所有的记录以及右表中连接字段相等的记录. ...

  9. sql中的left join、right join、inner join

    sql中的left join.right join.inner join 转自:http://www.cnblogs.com/pcjim/articles/799302.html left join( ...

最新文章

  1. galaxy android 8,三星终于正式升级安卓8.0!Galaxy S8尝鲜
  2. app 404 html,静态页面错误404(Flask框架)
  3. Flutter开发之JSON及序列化(29)
  4. java.sql.SQLException: The server time zone value ‘Öйú±ê׼ʱ¼ 解决方案
  5. php代码实现做网络安全的功能,基于PHP关键词审计技巧?网络安全源代码审计
  6. 有关子矩阵最大累加和的总结
  7. PHP7.0连接DB
  8. 在线教育音视频质量评价与感知系统
  9. Android, WindowsPhone7, IOS ,vc2010平台40多套图片滤镜开源
  10. vs2010报错:转换到 COFF 期间失败: 文件无效或损坏 解决方法
  11. Redis入门指南之一(简介)
  12. Java程序员必读书籍推荐
  13. 使用java代码返回树形结构的damo
  14. 引领5G智慧全场景 荣耀V30系列抢跑2020年市场
  15. 【总结】C#上传excel文件到Sql server数据库
  16. js 获取系统时间
  17. greasemonkey油猴详解
  18. 初入react.js
  19. Wio Terminal 有什么好玩的?
  20. Android 图片全屏适配各种屏幕小技巧

热门文章

  1. 小贝SEO博客_专注于SEO优化_软件_活动分享
  2. ps grep 不包括grep本身
  3. word标题前面存在竖线
  4. Windows下安装Redis及可视化工具
  5. 【Java设计模式】工厂方法
  6. 【配准论文解读】Color Point Cloud Registration with 4D ICP Algorithm
  7. 清华规划院 伟景行 诚聘 Jsp/Java/Web高级开发工程师 互联网开发主管 测试工程师 etc.
  8. 如何进行PDF文件翻译?PDF翻译怎么操作
  9. linux install jkd
  10. 三位学霸要去 IPO 敲钟:出身姚班,做出 300 亿估值