当前位置: 首页 > news >正文

SQL Zoo 6.The JOIN operation

以下数据均来自SQL Zoo

1.Modify it to show the matchid and player name for all goals scored by Germany. To identify German players, check for: teamid = 'GER'.(它以显示德国所有进球的比赛和球员名字,识别德国球员)

SELECT matchid,player FROM goal where teamid = 'GER'

2.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.(从之前的查询中你可以看到拉斯·本德在1012场比赛中进了一个球。现在我们想知道那场比赛是哪支球队.)

SELECT id,stadium,team1,team2FROM game where id = 1012

3.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.(每个进球的球员(来自进球)和球场名称(来自比赛表),修改它以显示球员,球队,球场和每个德国队进球的候选人)

SELECT player,teamid,stadium,mdateFROM game JOIN goal ON (id=matchid) where teamid = 'GER'

4.Show the team1, team2 and player for every goal scored by a player called Mario player LIKE 'Mario%'(显示team1, team2和球员的每一个进球被称为马里奥球员)

select team1,team2,player from game join 
goal on game.id = goal.matchid where player like 'Mario%'

5.Show playerteamidcoachgtime for all goals scored in the first 10 minutes gtime<=10.(显示球员,球队,教练,gtime前10分钟内所有进球的gtime<=10)

select player,teamid,coach,gtime from goal 
join eteam on goal.teamid = eteam.id where gtime <=10

6.List the dates of the matches and the name of the team in which 'Fernando Santos' was the team1 coach.(请列出比赛日期和“费尔南多·桑托斯”担任教练的球队名称)

select mdate,teamname from game 
join eteam on game.team1 = eteam.id where coach = 'Fernando Santos'

7.List the player for every goal scored in a game where the stadium was 'National Stadium, Warsaw'(列出在比赛场地为“华沙国家体育场”的比赛中每个进球的球员)

select player from game 
join goal on game.id = goal.matchid where stadium = 'National Stadium, Warsaw'

8.Show the name of all players who scored a goal against Germany.(显示所有在对阵德国队的比赛中进球的球员的名字)

SELECT distinct playerFROM game JOIN goal ON matchid = id WHERE (team1='GER' or team2='GER') and teamid != 'GER'

9.Show teamname and the total number of goals scored.(显示球队名称和总进球数)

SELECT teamname,count(teamid)FROM eteam JOIN goal ON id=teamidgroup BY teamname

10.Show the stadium and the number of goals scored in each stadium.(显示体育场和每个体育场的进球数)

select stadium,count(matchid) from game 
join goal on game.id = goal.matchid group by stadium

11.For every match involving 'POL', show the matchid, date and the number of goals scored.(对于每一场涉及“POL”的比赛,显示比赛日期和进球数)

select matchid,mdate,count(*) from game 
join goal on id = matchid where team1 = 'POL' or team2='POL' group by matchid

12.For every match where 'GER' scored, show matchid, match date and the number of goals scored by 'GER'(对于每一场“GER”进球的比赛,显示比赛,比赛日期和“GER”进球的数量)

select matchid,mdate,count(teamid) from game 
join goal on id = matchid where teamid = 'GER' group by matchid

13.List every match with the goals scored by each team as shown. If it was a team1 goal then a 1 appears in score1, otherwise there is a 0.  You could SUM this column to get a count of the goals scored by team1.  Sort your result by mdate, matchid, team1 and team2.(列出每一场比赛,如果是team1的进球,则score1中显示1,否则显示0。您可以对这一列进行求和,以获得team1得分的总数。按候选人、配对、team1和team2对结果进行排序。)

SELECT mdate,team1,SUM(CASE WHEN teamid=team1 THEN 1 ELSE 0 END) score1,team2,SUM(CASE WHEN teamid=team2 THEN 1 ELSE 0 END) score2
FROM game 
LEFT JOIN goal 
ON matchid = id
GROUP BY mdate, matchid, team1, team2

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【c++】类和对象 (中) (类的默认成员函数)
  • Springboot 实现 Modbus Rtu 协议接入物联网设备
  • matlab实现红绿灯识别
  • MySQL事务隔离级别、InnoDB使用MVCC+各种锁实现了RC和RR事务隔离级别、具体案例
  • cpio 命令
  • element-ui周选择器,如何获取年、周、起止日期?
  • C# Type 对象序列化与反序列化
  • 合并两个有序数组(LeetCode)
  • oracle创建dblink使得数据库A能够访问数据库B表LMEAS_MFG_FM的数据
  • sql获取过去的小时数
  • vue请求springboot接口下载zip文件
  • 【书生大模型实战营第三期 | 入门岛第3关-Git 基础知识】
  • java并发包AtomicInteger类
  • PHP之docker学习笔记
  • uni-app接人腾讯地图
  • [译] 理解数组在 PHP 内部的实现(给PHP开发者的PHP源码-第四部分)
  • [原]深入对比数据科学工具箱:Python和R 非结构化数据的结构化
  • “大数据应用场景”之隔壁老王(连载四)
  • 345-反转字符串中的元音字母
  • css选择器
  • exports和module.exports
  • httpie使用详解
  • java多线程
  • Java精华积累:初学者都应该搞懂的问题
  • JS实现简单的MVC模式开发小游戏
  • nodejs实现webservice问题总结
  • SpringBoot几种定时任务的实现方式
  • Terraform入门 - 1. 安装Terraform
  • Vue学习第二天
  • 简析gRPC client 连接管理
  • 模仿 Go Sort 排序接口实现的自定义排序
  • 排序(1):冒泡排序
  • 前端js -- this指向总结。
  • 如何利用MongoDB打造TOP榜小程序
  • 数据库写操作弃用“SELECT ... FOR UPDATE”解决方案
  • hi-nginx-1.3.4编译安装
  • LIGO、Virgo第三轮探测告捷,同时探测到一对黑洞合并产生的引力波事件 ...
  • raise 与 raise ... from 的区别
  • Spring Batch JSON 支持
  • 支付宝花15年解决的这个问题,顶得上做出十个支付宝 ...
  • ​【经验分享】微机原理、指令判断、判断指令是否正确判断指令是否正确​
  • ​Java基础复习笔记 第16章:网络编程
  • ## 基础知识
  • #stm32驱动外设模块总结w5500模块
  • #微信小程序(布局、渲染层基础知识)
  • (19)夹钳(用于送货)
  • (C语言)字符分类函数
  • (javascript)再说document.body.scrollTop的使用问题
  • (动手学习深度学习)第13章 计算机视觉---图像增广与微调
  • (力扣)1314.矩阵区域和
  • (三) diretfbrc详解
  • (三)Hyperledger Fabric 1.1安装部署-chaincode测试
  • (十)T检验-第一部分
  • (转)淘淘商城系列——使用Spring来管理Redis单机版和集群版
  • *上位机的定义