我正在询问酒店预订和预订系统,但我遇到了一个问题选择房间没有在两个日期之间保留。 我的查询是相似的,但它没有工作,查询返回注意但实际上我有3个房间类型1的房间。 Sql小提琴:http://sqlfiddle.com/#!2/b97419
SELECT tbl_room.room_no, tbl_room.type_id, tbl_Reservation.room_id
FROM tbl_room
LEFT JOIN tbl_Reservation ON tbl_room.id = tbl_Reservation.room_id
WHERE (
(
tbl_Reservation.checkin_data < '" . $checkin . "'
AND tbl_Reservation.checkout_data < '" . $checkin . "'
)
OR (
tbl_Reservation.checkin_data > '" . $checkout . "'
AND tbl_Reservation.checkout_data > '" . $checkout . "'
)
)
AND tbl_room.type_id =1
感谢您的帮助,抱歉我的英语不好。
答案 0 :(得分:1)
尝试这样的事情
SELECT
tbl_room.room_no,
tbl_room.type_id,
tbl_room.id,
tr.id as reserv_status
FROM tbl_room
LEFT JOIN tbl_Reservation tr ON tbl_room.id = tr.room_id AND
(
(tr.checkin_data <= "'$checkin'" AND tr.checkout_data >= "'$checkin'")
OR
(tr.checkin_data <= "'$checkout'" AND tr.checkout_data >= "'$checkout'")
)
WHERE
tbl_room.type_id =1 AND tr.id IS NULL