-1

下表是:
Flight (FlightID, MaxCapacity)
FlightBooking (BookingID, FlightID, NumSeats, Status),状态为:Reserved、Held、Expired、Cancall。

我已经知道如何显示保留和保留席位,但我无法计算应等于 MaxCapacity 减去保留和保留席位的可用席位。

请问有什么建议吗?

4

2 回答 2

0
SELECT f.MaxCapacity - COUNT(b.Status)
FROM Flight f
INNER JOIN FlightBooking b
ON f.FlightID = b.FlightID
WHERE b.Status IN ('Reserved','Held')
GROUP BY f.FlightID
于 2013-04-17T15:11:57.887 回答
0
select flightid, 
       max(f.maxcapacity) - count(case when fb.status in ('reserved', 'held') 
                                       then 1 
                                       else 0 
                                  end)
from flight f
left outer join flightbooking fb on fb.flightid = f.flightid
group by f.flightid
于 2013-04-17T15:12:19.350 回答