这里似乎有很多冗余。有没有更高效的方法,还是需要使用工会? inner join
也在那里,因为players
表没有酒店信息,必须从teams
中检索。有没有更有效的方法来编写这个简单的SQL查询?
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';