0

我试图找到比赛中的裁判(他是官员)也为主队和客队提供医疗服务的比赛(请参阅下面的关系图)。

我试过这个,但它没有返回任何记录:

select matches.id,
matches.home,
matches.away,
matches.referee
from matches
join officials on officials.staffid = matches.referee
join medicalservices on medicalservices.team in (matches.home, matches.away)
where medicalservices.team = matches.home
and medicalservices.team = matches.away;

我猜它不会返回记录,因为最后两行,但我不知道我还能如何确保同一个官员为两支球队提供医疗服务。

下面是关系图供参考:

在此处输入图像描述

4

1 回答 1

1

您需要加入医疗服务两次,一次是寻找提供给主队的服务,一次是寻找提供给客队的服务。然后您可以检查为每个团队提供的服务是否由同一裁判员提供。

您也不需要官员表。

select matches.id,
matches.home,
matches.away,
matches.referee
from matches
join medicalservices home_medservices on home_medservices.team  = matches.home
join medicalservices away_medservices on away_medservices.team = matches.away
where home_medservices.official = matches.referee
  and away_medservices.official = matches.referee
于 2013-05-10T20:55:15.517 回答