在我尝试开发酒店预订系统时,我很好奇哪种方法最适合系统架构。目前,当客户在特定日期预订酒店房间时,我会获得酒店房间详细信息,客户详细信息和预订详细信息。
可用房间=总房间 - 预留房间
现在,我根据客户选择的特定日期保留的房间,使用查询检索该日期可用的房间。例如,客户从3 August 2016
到6 August 2016
预订房间。然后,我将在8月3日至8月6日期间从预订详情中检索日期。我将每天循环到这个SQL语句中。
Select * from bookingDetails where theDate between StartDate and EndDate and RoomType = 'Something'
然后我将把所设置的日期总结为预留的房间并获得总房间。 客户选择日期
时将触发此声明或者我应该再创建一个桌子作为可用房间,并将5年日历与总房间存储在一起。它将推断客户何时预订房间。
答案 0 :(得分:0)
我认为你不需要任何其他表格 您只需要查找所有预订的房间并将其排除在外:
Select *
from tbl_Rooms
WHERE RoomType = 'Something' and
Room_ID not in (
Select Room_ID
from bookingDetails
where theDate between @StartDate and @EndDate
);
但是,该查询返回的房间仅在整个期间可用。以下是按天显示所有可用房间的查询(在255天范围内):
;WITH Pass0 as (SELECT * FROM (VALUES (1),(1),(1),(1)) as A(C)),
Pass1 as (select 1 as C from Pass0 as A, Pass0 as B),--16 rows
Pass2 as (select 1 as C from Pass1 as A, Pass1 as B),--256 rows
Dates as (SELECT DATEADD(d,ROW_NUMBER() OVER(ORDER BY (SELECT NULL))-1,@StartDate) as AvailDate FROM Pass2)
SELECT d.AvailDate, r.* FROM tbl_Rooms as r
INNER JOIN Dates as d ON AvailDate < @EndDate
WHERE NOT EXISTS (SELECT 1 FROM bookingDetails as b WHERE b.theDate = d.AvailDate and b.Room_ID = r.Room_ID)
ORDER BY r.Room_Number, d.AvailDate;