0

我正在尝试获取每家酒店在特定日期未预订客房的所有损失收入的总和。

  • 酒店 (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
4

1 回答 1

1

显而易见的事情是错误的括号SUM。此外,ORDER BY应该在之后GROUP BY,您需要以不同的方式转换日期

SELECT hotelNo, 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)
GROUP BY hotelNo
ORDER BY hotelNo
于 2013-11-12T23:57:10.610 回答