[英]Mysql query for booking car and driver for given interval of time
我有4列的MySQL表-驱动程序,开始日期,结束日期,汽车。 现在,我需要向预订驾驶员写查询,如果驾驶员和汽车在特定时间(在开始时间和结束时间之间)空闲,那么可以预订驾驶员和汽车。 如果驾驶员免费但汽车不免费(由他人预订),则也不能预订驾驶员(意味着预订失败),因为汽车不可用。
我尝试这样,但没有得到正确的答案。
select * from driver
where DiverName=?
and Car=? between StartDateTime=? and EndDateTime=?
select StartDateTime='2014-11-28 12:59:00' and EndDateTime=' 2014-12-31 13:59:00 '
from driver
where DriverName='rohit' or CarDetails='discover'
这些我现在错了,但是请给我正确的一个查询plz。 永远记住,我们需要时间间隔内的汽车和驾驶员自由
让我们声明一下您想要了解驾驶员和汽车是否免费的时间:
Declare @time datetime
Set @time = '2014-11-28 12:59:00'
然后,您可以使用以下方法查找是否有免费的驾驶员和汽车:
select * from driver
where @time not between StartDateTime and EndDateTime
这将向您显示,是否有在特定时间免费的汽车和驾驶员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.