表:
Flights(Flno, Origin, Destination, Distance, departs, Arrives) <br>
Flight Instance(Flno, Day, Aid)<br>
Aircraft(Aid, Make, Model, CrusingRange)<br>
Certied(Eid, Make, Model)<br>
Employee(Eid, Ename, Salary)<br>
Fight Attendant(Flno, Day, Eid, Role)<br> <br>
我知道如何用关系代数写它,它将是:
∏开斋节,目的地(σeid,目的地(Flight_Attendant flno=flno * 航班((/∏目的地(σ目的地(航班((
如何在sql中转换它? 所以结果将是去过所有城市的员工名单。
也许是这样的:
SET @TotalDestinations = (SELECT COUNT(AUX.Destination) FROM
(select distinct Destination from Flights) AS AUX);
SELECT A.eid, Employee.Ename -- select only those who traveled to all destinations
FROM
(
-- know all the destinations for all assistant
SELECT DISTINCT Flight_attendant.eid, Flights.Destination
FROM Flight_attendant
INNER JOIN Flights ON Flight_attendant.flno=Flights.flno
) AS A
INNER JOIN Employee ON Employee.Eid = A.Eid
GROUP BY A.eid, Employee.Ename
HAVING COUNT(*) = @TotalDestinations