SELECT DISTINCT
Room.RoomID,
Room.RoomNumber,
Room.PhoneExtension,
Room.SpecialNotes ,
RoomType.Description
FROM
Room
INNER JOIN
RoomType
ON
Room.TypeID = RoomType.TypeID
LEFT JOIN
Reservation
ON
Room.RoomID = Reservation.RoomID
WHERE
Room.DeleteFlag=0 AND
(Reservation.ResStatus <> 'Occupied' OR Reservation.ResStatus = NULL) AND
(Reservation.ResStatus <> 'Reserved' OR Reservation.ResStatus = NULL) AND
(Reservation.ResStatus <> 'Confirmed' OR Reservation.ResStatus = NULL)
ORDER BY
RoomNumber
您好,我有一个删除房间表单,应该在数据库中将房间标记为已删除。房间ID也会在预订时发布到预订表。我试图获得所有未出现在预订中的房间,或者如果它们在那张桌子中,那么它们就不应该被保留,占用或确认。
该查询将退回所有预订时专用的房间,无论预订状态如何,没有预订状态的房间。
任何提示都将不胜感激。
答案 0 :(得分:1)
也许我误解了你的问题,但试试这个:
SELECT DISTINCT
Room.RoomID,
Room.RoomNumber,
Room.PhoneExtension,
Room.SpecialNotes ,
RoomType.Description
FROM Room
INNER JOIN RoomType ON Room.TypeID = RoomType.TypeID
/*LEFT JOIN Reservation ON Room.RoomID = Reservation.RoomID*/
WHERE Room.DeleteFlag=0 And Room.RoomID not in (select RoomID from Reservation where
(Reservation.ResStatus <> 'Occupied' OR Reservation.ResStatus = NULL)
AND (Reservation.ResStatus <> 'Reserved' OR Reservation.ResStatus = NULL)
AND (Reservation.ResStatus <> 'Confirmed' OR Reservation.ResStatus = NULL))
ORDER BY RoomNumber