简体   繁体   English

酒店预订检查抵达日期和离开日期之间的空房间?

[英]hotel booking check empty room between arrival date and departure date?

Basically i retrieve all available room with arrival and departure date from the room table.基本上,我从房间表中检索所有带有到达和离开日期的可用房间。

SQL Query SQL查询

SELECT * FROM `roomcalendar` where day BETWEEN '2016-08-25' and '2016-08-31'

Result is结果是

id day        roomname avaroom
 1 2016-08-25 RoomA          0
 2 2016-08-26 RoomA          2
 3 2016-08-27 RoomA          0
 4 2016-08-28 RoomA          1
 5 2016-08-29 RoomA          1
 6 2016-08-30 RoomA          0
 7 2016-08-31 RoomA          1

I just want available room if avaroom not equal to 0 beteen arrival date and departure date如果 avaroom 不等于到达日期和离开日期之间的 0,我只想要可用房间

And I want the result我想要结果

SQL Query SQL查询

SELECT * FROM `roomcalendar` where day BETWEEN '2016-08-25' and '2016-08-31'

it must be empty result结果必须是空的

SQL Query SQL查询

 SELECT * FROM `roomcalendar` where day BETWEEN '2016-08-25' and '2016-08-26'

it must be empty result结果必须是空的

SQL Query SQL查询

 SELECT * FROM `roomcalendar` where day BETWEEN '2016-08-26' and '2016-08-27'

it show one result它显示一个结果

SQL Query SQL查询

SELECT * FROM `roomcalendar` where day BETWEEN '2016-08-26' and '2016-08-28'

it must be empty result结果必须是空的

SQL Query SQL查询

SELECT * FROM `roomcalendar` where day BETWEEN '2016-08-28' and '2016-08-30'

it show two result它显示两个结果

Thanks.谢谢。

I just want available room if avaroom not equal to 0 beteen arrival date and departure date如果 avaroom 不等于到达日期和离开日期之间的 0,我只想要可用房间

So if you reformulate this:所以如果你重新表述这个:

  • you want the room if there is no row where avaroom = 0 between two dates.如果两个日期之间没有avaroom = 0 的行,则您想要房间。

Translated in SQL:用 SQL 翻译:

select * from roomcalendar
where day between '2016-08-25' and '2016-08-31'
and not exists (
  select * from roomcalendar
  where day between '2016-08-25' and '2016-08-31'
  and avaroom = 0
);

You can also reformulate by saying:你也可以这样说:

  • you want the room if the number of rows where avaroom is not 0 is the total number of rows expected (in this case, this corresponds to the amount of days)如果 avaroom 不为 0 的行数是预期的总行数(在这种情况下,这对应于天数),则您想要房间

Translated in SQL:用 SQL 翻译:

select * from roomcalendar
where day between '2016-08-25' and '2016-08-31'
and avaroom != 0
having count(*) = datediff('2016-08-31','2016-08-25') + 1

You might have to tweak the queries a bit, but that should point you to the right direction.您可能需要稍微调整查询,但这应该为您指明正确的方向。

Modify the query like this.像这样修改查询。

SELECT * FROM `bookings` WHERE `room_id` = '1' 
AND booking_end >= '2020-12-01 13:20:00' AND booking_start <= '2020-12-10 13:20:00'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM