我需要使用包含以下表格的数据库编写一堆查询:
Match(homeId, awayId, homeScore, awayScore, date)
League(leagueId, leagueName)
Player(playerId, teamId, playerName, age, position, marketValue, position)
Team(teamId, teamName, leagueId, city)
但是,我无法弄清楚如何为以下查询编写SQL查询:
"找到拉齐奥在米兰主场击败米兰的最新日期。" 要么 "查找至少有一个团队至少有三个团队的联赛名称 守门员"
如何使用匹配表加入Team表,该表将为我提供包含团队名称的匹配项。 (即homeId,awayId,homeName,awayName)并写下这两个查询。
感谢。
答案 0 :(得分:0)
对于您的第一个要求,您可以使用类似的东西。
select date
from match
where homeid =(select teamid from team where teamname = 'Milan')
and awayId = (select teamid from team where teamname = 'Lazio')
and homeScore < awayScore
第二,使用下面的内容。
select l.leagueName
from league l
inner join Team t
on l.leagueid=t.leagueid
where t.teamid in (
select distinct(teamid) as teamid from player p
where p.position like 'Goalkeeper'
group by teamid
having count(*) >= 3)