我正在尝试获取每家酒店在特定日期未预订客房的所有损失收入的总和。
- 酒店 (hotelNo,hotelName,hotelAddress)
- 房间(hotelNo,roomNo,type,price)
- 来宾 (guestNo,guestName,guestAddress)
- Booking (hotelNo,guestNo,dateFrom,dateTo,roomNo)
这是我到目前为止的命令。我觉得这只是一个愚蠢的错误,我错过了一些简单的东西,但我就是不能把手指放在它上面。
SELECT hotelNo, roomNo, (SUM)price AS "Lost Income"
FROM room r
WHERE roomNo NOT IN
(SELECT roomNo FROM booking b
WHERE to_date('20080706', 'yyyymmdd')
BETWEEN dateFrom AND dateTo
AND r.hotelno = b.hotelno)
ORDER BY hotelNo
GROUP BY hotelNo