寻找空闲房间(预订系统)

2023-12-05

对于预订系统,我有一张包含房间、到达和离开的表格。

示例数据:

id | room | arrival    | departure
---+------+------------+-----------
1  | 1    | 2011-03-12 | 2011-03-14
2  | 1    | 2011-03-08 | 2011-03-09
3  | 1    | 2011-03-19 | 2011-03-20
4  | 2    | 2011-03-22 | 2011-03-30 
5  | 2    | 2011-03-19 | 2011-03-22

我现在的问题是:如果我有新的预订(2011-03-10 to 2011-03-12),如何查看哪些房间是空闲的?

此示例的输出应该是 room1 and 2.


以下查询将显示某个日期范围内的非免费房间:

select room from bookings where
(arrival<'2011-03-12' and departure>='2011-03-12') -- overlap at the end
OR (arrival<='2011-03-10' and departure>'2011-03-10') -- overlap at the start
OR (arrival>='2011-03-10' and departure<='2011-03-12') -- complete overlap

你可以使用它

select roomnumber from rooms where roomnumber not in (... as above ...)

寻找免费房间

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

寻找空闲房间(预订系统) 的相关文章

随机推荐