本文介绍了检查两个日期是否不在另一个日期+ MYSQl之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在查询酒店预订和预订系统的查询,但是在选择两个日期之间未预订房间时遇到了问题.我的查询与此类似,但是它不能正常工作,查询返回注意,但实际上我有3个房间,房间类型为1.SQL提琴手: http://sqlfiddle.com/#!2/b97419
I am writhing a query for a hotel reservation and booking system but I got a problem with selecting rooms was not reserved between two date . my query is alike this but it's not working as well and query return noting but actually I have 3 room with room type 1 .Sql fiddle : 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
感谢您的帮助,对不起我的英语不好.
thanks for your helping and sorry for my bad english .
推荐答案
尝试类似的方法
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
这篇关于检查两个日期是否不在另一个日期+ MYSQl之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!