用于表预留的两个数据时间之间的SQL命令 [英] SQL command between two datetimes for table reservation

查看:114
本文介绍了用于表预留的两个数据时间之间的SQL命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个总是满员的餐厅预订系统,如果有人想来的话,您必须预订。

I am developing at the moment the reservation system for a restaurant that is always full and if anyone wants to come must make your reservation.

这意味着主机进入到达和离开,所以主机想要在餐厅的确切时间间隔。

This means that the host enters arrival and departure, so the exact interval in which the host wants to be in the restaurant.

所以如果客户A在晚上8点到晚上10点有客人到达B,谁想要晚上9点到晚上11点想要预订与客户A系统相同的表不会放弃,因为时间重叠。

$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')

我目前的命令是有效的,但我相信更容易。

I am currently command that works, but I believe it would be much easier.

This is how it works, but unfortunately it happens sometimes that a table is available when it is reserved.

因此,寻求更好的解决方案,因为餐厅是约100个表,我相信有时可能会发生服务器无法确定是否保留表。

Therefore, seeking a better solution, because the restaurant is approximately 100 tables and I believe that sometimes it can happen that the server does not manage to find out whether a table is reserved.

推荐答案

我会减少到以下:

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

如果表格被预留,查询结果应为空。不确定'odchodHosta'字段是否有效。

Query result should be empty if table is reserded. Not sure how 'odchodHosta' field works.

//更新SQL-添加NOT

//Update SQL- Added NOT

这篇关于用于表预留的两个数据时间之间的SQL命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆