我正在开发一个餐厅的预订系统,这个系统总是客满的,如果有人想来,必须为您预订。
这意味着主人进入到店和离开店,所以主人希望在餐厅的确切时间间隔。
So if that customer A has a reservation 8:00 p.m. to 10:00 p.m. and customer arrives B, who wants to come 9:00 p.m. to 11:00 p.m. and wants to book the same table as the customer A system will not let go, because the times overlap .

$GuetComming = '2014-01-21 12:30:00'
$GuestDepature = '2014-01-21 16:30:00'
$i= '10'

SQL查询:
SELECT * FROM `booking`
    where (Table='$i' AND Comming BETWEEN '$GuestComming' AND '$GuestDepature')
    or (Table='$i' AND Depature BETWEEN '$GuestComming' AND '$GuestDepature')
    or (Table='$i' AND Comming <= '$GuestComming' AND Depature >='$GuestDepature')
    or (Table='$i' AND Comming BETWEEN '$GuestComming' AND '$GuestDepature')

我现在是命令,但我相信这会容易得多。
This is how it works, but unfortunately it happens sometimes that a table is available when it is reserved.

因此,寻求更好的解决方案,因为餐厅approximately 100 tables,我相信有时可能会发生服务器无法找到是否预订了一张桌子的情况。

最佳答案

我将把它简化为:

SELECT * FROM `booking`
WHERE Table='$i' AND NOT(Comming >= '$GuestDepature' OR Depature <= '$GuestComming')

如果重新排序表,则查询结果应为空。不知道“奥德霍斯塔”是怎么工作的。
//更新SQL-未添加

关于mysql - 两个日期时间之间的SQL命令用于表保留,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21255043/

10-11 22:29
查看更多