我有MySQL表“ room_booking”,该表包含两列“ start_time”和“ end_time”。我想检查一下会议室的预定时间。假设从2:10 PM到3:15 PM预订了房间。然后,此时不应插入另一个条目。 我的查询是
$queryCheck = "SELECT start_time,end_time FROM room_booking AND (SELECT * FROM (room_booking) WHERE (start_time NOT BETWEEN '".$new_start_time."' AND '".$end_start_time."') AND (end_time NOT BETWEEN '".$new_start_time."' AND '".$end_start_time."'))";
答案 0 :(得分:0)
在我看来,这只是重叠范围问题,在这种情况下,您想返回与输入开始时间和结束时间不重叠的记录。尝试以下查询:
SELECT *
FROM room_booking
WHERE existing_end < ? OR existing_start > ?;
对于上面的两个?
占位符,您将按顺序绑定$new_start_time
和$end_start_time
。因此,您将得到以下查询:
SELECT *
FROM room_booking
WHERE existing_end > $new_start_time OR existing_start > $end_start_time;
答案 1 :(得分:0)