hi,
I am currently working on the hospital room booking system. In this, I want to display vacant rooms from the given date range. Even if single day vacant it should pick up. Kindly share your ideas or a sample query
I am having two tables one room master and another is a temp_booking table.
I want to find out from room master which rooms are vacant for a given date range. Room master contains room no, room category and temmp_booking is used for booking which contains room no, book_from_date and book_to_date
Eg:
Start date - 01/01/2018
end date - 01/15/2018
room category - 'Deluxe suite'
Total rooms in this category - 6 (Ds-1, DS-2......DS-6)
Room No Category book_from_date book_to_date
DS-1 Deluxe Suite 01/01/2018 01/15/2018
Ds-2 Deluxe Suite 01/04/2018 01/15/2018
Ds-3 Deluxe Suite 01/01/2018 01/10/2018
from the above table, I want to display Ds-2 and Ds-3 and also the remaining rooms DS-4, DS-5 and also 6 when I check for room availability from 01/01/2018 to 01/15/2018.
Because DS-2 is vacant from 01/01/2018 to 01/03/2018 and DS-3 is vacant from 01/11/2018 to 01/15/2018 and remaining 3 rooms have no booking. Hope you got it. Want to list this on the priority basis.
What I have tried:
SELECT r.Room_No
FROM room_master AS r
WHERE room_catg = 'Deluxe Suite'
AND r.room_no NOT IN (SELECT t1.room_no
FROM Room_Master t1
INNER JOIN temp_booking t2 ON t1.room_no = t2.room_no
WHERE NOT (Book_To_Date < '01/01/2018') OR ([Book_To_Date] > '01/15/2018'))
This query displaying the rooms which are fully vacant for the given date range.