表保留
table roominventory
餐厅
我正在做房间预订系统。
我已经查询了房间的日期可用性:
SELECT r.roominv_id,r.room_id
FROM roominventory r
WHERE r.roominv_id
NOT IN
(SELECT b.roominv_id
FROM reserve b
WHERE NOT (b.chckout < '$chckin'
OR
b.chckin > '$chckout'))
我的问题是,在哪里可以在我的查询中插入条件,我可以根据房间的空房情况选择特定房型。
我知道它就像room.room_type LIKE '%$roomtype%'
,但我不知道我会插入哪个查询部分。
答案 0 :(得分:2)
以下是使用LEFT JOIN
并检查NULL
的替代方法:
SELECT
r.roominv_id,
r.room_id
FROM roominventory AS r
INNER JOIN room AS m ON m.room_id = r.room_id
LEFT JOIN reserve res ON r.roominv_id = res.roominv_id AND
NOT (b.chckout < '$chckin' OR b.chckin > '$chckout')
WHERE m.room_type LIKE '%$roomtype%'
AND res.roominv_id IS NULL
祝你好运。
答案 1 :(得分:1)
你可以JOIN
room
这样的表{/ 1}}:
SELECT
r.roominv_id,
r.room_id
FROM roominventory AS r
INNER JOIN room AS m ON m.room_id = r.room_id
WHERE m.room_type LIKE '%$roomtype%'
AND r.roominv_id NOT IN (SELECT b.roominv_id
FROM reserve b
WHERE NOT (b.chckout < '$chckin'
OR
b.chckin > '$chckout'));