我的作业需要一个 sql 查询。查询必须返回正确的结果。
我的错误查询:
SELECT RZ.* FROM TBL_HOTEL_RESERVATION AS RZ
INNER JOIN TBL_HOTEL_ROOM AS ROOM
ON ROOM.ROOM_CODE <> RZ.ROOM_CODE
WHERE
(CONVERT(DATETIME,LEFT(RZ.ARRIVAL_TIME,12)) <= CONVERT(DATETIME,LEFT('3/12/2013',12))
AND
CONVERT(DATETIME,LEFT(RZ.LEAVE_TIME,12)) > CONVERT(DATETIME,LEFT('3/12/2013',12)))
OR
(CONVERT(DATETIME,LEFT(RZ.ARRIVAL_TIME,12)) < CONVERT(DATETIME,LEFT('3/14/2013',12))
AND
CONVERT(DATETIME,LEFT(RZ.LEAVE_TIME,12)) >= CONVERT(DATETIME,LEFT('3/14/2013',12)))
例如
room no : 1040
first reservation: 12 march 2013 -15 march 2013
second reservation: 13 march 2013 - 16 march 2013
我正在尝试,如果房间有这些日期范围的预订,则不应进行第二次预订。