我的酒店数据库有五个表和一个可用于预订的网络界面。 网络界面能够根据价格、客人数量和酒店位置消除可用房间。但是,我无法弄清楚如何根据已预订的日期来消除房间。
数据库看起来像这样
表格房型
ID - int
Type - varchar
Price - int
maxGuests - int
餐 table 上的客人
ID - int
name - varchar
email - varchar
simi - varchar
表格位置
ID - int
name - varchar
table 位室
ID - int
typeID - int(refernces type.ID)
hotelID - int(references locations.ID)
餐 table 预订
ID - int
guestID - int(references guests.ID)
hotelID - int(references locations.ID)
roomID - int(references rooms.ID)
arrivalDate - date
leavingDate - date
因此,我用来消除房间的 SQL 查询如下所示:
SELECT rooms.ID, type.type, type.price
FROM rooms
INNER JOIN type ON rooms.typeID = type.ID
WHERE rooms.hotelID = $hotelLocation
AND room.typeID = $roomType
AND type.maxGuests >= $numberOfGuests
我一直在想,我可能需要使用子查询从预订表中选择日期,并将这些日期与用户通过 Web 界面输入的日期进行比较。但我不知道如何实现它。
最佳答案
SELECT rooms.ID, type.type, type.price
FROM rooms
INNER JOIN type ON rooms.typeID = type.ID
WHERE rooms.hotelID = $hotelLocation
AND room.typeID = $roomType
AND type.maxGuests >= $numberOfGuests
AND NOT EXISTS (
SELECT 1
FROM bookings
WHERE bookings.roomID = rooms.roomID
-- Depending on the interpretation of arrivalDate and
-- leavingDate, the comparators may need to be <= and >=
AND bookings.arrivalDate < $requestedLeavingDate
AND bookings.leavingDate > $requestedArrivalDate
)
关于php - 我正在建立一个酒店数据库,但似乎不知道如何删除已经预订的房间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28752418/