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'.(它以显示德国所有进球的比赛和球员名字,识别德国球员)

sql 复制代码
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场比赛中进了一个球。现在我们想知道那场比赛是哪支球队.)

sql 复制代码
SELECT id,stadium,team1,team2
  FROM 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.(每个进球的球员(来自进球)和球场名称(来自比赛表),修改它以显示球员,球队,球场和每个德国队进球的候选人)

sql 复制代码
SELECT player,teamid,stadium,mdate
  FROM 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和球员的每一个进球被称为马里奥球员)

sql 复制代码
select team1,team2,player from game join 
goal on game.id = goal.matchid where player like 'Mario%'

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

sql 复制代码
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.(请列出比赛日期和"费尔南多·桑托斯"担任教练的球队名称)

sql 复制代码
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'(列出在比赛场地为"华沙国家体育场"的比赛中每个进球的球员)

sql 复制代码
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.(显示所有在对阵德国队的比赛中进球的球员的名字)

sql 复制代码
SELECT distinct player
  FROM 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.(显示球队名称和总进球数)

sql 复制代码
SELECT teamname,count(teamid)
  FROM eteam JOIN goal ON id=teamid
 group BY teamname

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

sql 复制代码
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"的比赛,显示比赛日期和进球数)

sql 复制代码
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"进球的数量)

sql 复制代码
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对结果进行排序。)

sql 复制代码
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
相关推荐
独行soc16 分钟前
2025年渗透测试面试题总结-安恒[实习]安全服务工程师(题目+回答)
linux·数据库·安全·web安全·面试·职场和发展·渗透测试
Violet_Stray26 分钟前
mac下载、使用mysql
数据库·mysql·macos
liweiweili1261 小时前
解决 MySQL 错误 1356 (HY000)
数据库·mysql
杨凯凡1 小时前
MySQL函数触发:函数处理与触发器自动化应用
数据库·mysql
TDengine (老段)1 小时前
TDengine 在新能源领域的价值
java·大数据·数据库·人工智能·时序数据库·tdengine·涛思数据
镜舟科技2 小时前
时序数据库、实时数据库与实时数仓:如何为实时数据场景选择最佳解决方案?
数据库·物联网·数据分析·时序数据库·olap·实时数仓·实时数据库
麻雀无能为力2 小时前
CAU数据库class2 SQL语言
数据库·sql·oracle
夜松云3 小时前
Qt框架核心组件完全指南:从按钮交互到定时器实现
数据库·qt·交互·信号与槽·ui组件·容器类·定时器机制
计算机学姐3 小时前
基于SpringBoot的小型民营加油站管理系统
java·vue.js·spring boot·后端·mysql·spring·tomcat
Elastic 中国社区官方博客3 小时前
JavaScript 中使用 Elasticsearch 的正确方式,第一部分
大数据·开发语言·javascript·数据库·elasticsearch·搜索引擎·全文检索