这里似乎有很多冗余。有没有更有效的方法,还是需要使用工会?还有第inner join
一个是因为该players
表没有酒店信息并且必须从中检索teams
。
select players.name
from players
inner join teams
on players.team = teams.name
where teams.staysat = 'Ambassador'
and teams.checkin is not null
and teams.checkin < '18-AUG-07'
and teams.checkout > '18-AUG-07'
--
union all
select officials.name
from officials
where officials.staysat = 'Ambassador'
and officials.checkin is not null
and officials.checkin < '18-AUG-07'
and officials.checkout > '18-AUG-07'
--
union all
select fans.name
from fans
where fans.staysat = 'Ambassador'
and fans.checkin is not null
and fans.checkin < '18-AUG-07'
and fans.checkout > '18-AUG-07';