在给定参数为房间类型、开始日期和结束日期的情况下,检查可用房间


Check available rooms given parameters are room type,start date, and end date

我有这个表

**Rooms** 
idRoom
name
**Room_details**
idRoomDetails
idRoom
idRoomType
**Bookings**
idBooking
idRoomDetails
startDate
endDate

具有**的单词是表名

我拥有的变量有idRoomType、startDate和endDate。

如何输出所有可用的房间,并且给定的参数为room type,startDateendDate

老实说,我现在不知道如何开始,这就是为什么我不能向你展示我迄今为止所做的一切。

我们将非常感谢您的帮助!谢谢!:)

如果日期选择是你的问题,我可以给你一些有用的见解。您应该在查询结构中选择所有符合以下条件的房间;

Booking.startDate  <= "End date of the availability period you're checking"
Booking.endDate    >= "Start date of the availability period you're checking"

为了更清楚,您的查询可能看起来像:

SELECT * FROM Rooms
INNER JOIN Room_details ON Rooms.idRoom = Room_details.idRoom
LEFT JOIN Bookings ON Room_details.idRoomDetails = Bookings.idRoomDetails 
WHERE Bookings.idBooking IS NULL
OR (Bookings.startDate <= 'availabilityEndDate'
AND Bookings.endDate >= 'availabilityStartDate')

其中"availabilityEndDate"answers"availability StartDate"需要替换为课程的实际日期。

你能试试这个查询吗:

select * from Rooms r
inner join Room_details rd on
r.idRoom = rd.idRoom
left join Bookings b on
rd.idRoomDetails  = b.idRoomDetails 
where b.idBooking is null
and b.startDate > CURDATE()

和b.startDate>CURDATE()应该只检查那些将来有预订的房间。您可能想先尝试不使用此行的查询,看看它是否有效。如果它确实有效,那么您可以随时向查询添加日期检查部分。