我试图获得每个酒店在某一天没有预订房间的所有收入损失的总和。
这是我到目前为止的命令。我觉得这只是一个愚蠢的错误而且我错过了一些简单的东西,但我无法将手指放在上面。
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
答案 0 :(得分: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