I got a simple mysql table for already booked rooms. Here the sql structure:
CREATE TABLE Rooms (
`ID` int, `Description` varchar(50)
);
INSERT INTO Rooms values
(123, 'Room in Frankfurt'),
(234, 'Room in Wiesbaden'),
(245, 'Room in Darmstadt');
CREATE TABLE Bookings (
`ID` int, `StartTime` datetime, `EndTime` datetime, `post_ID` int
);
INSERT INTO Bookings
(`ID`, `StartTime`, `EndTime`, `post_ID`)
VALUES
(1, '2018-01-05', '2018-04-05', 123),
(2, '2018-08-01', '2018-10-01', 123),
(3, '2019-02-01', '2019-06-01', 123),
(4, '2018-02-01', '2018-06-01', 234),
(5, '2018-08-01', '2018-09-01', 294),
(6, '2018-09-01', '2018-11-30', 234),
(7, '2018-11-01', '2018-12-30', 294)
;
In this table we can see all bookings for all rooms we have. My problem is to find a SQL Query to find free slots for a room. The user can give these parameters:
- a date for the earliest check-in (ex: 2018-10-01)
- a date for the latest check-in (ex: 2018-10-15)
- a maximum period in months (example: 3 months)
So the user needs a room for 3 months, starting from 01-15. October 2018.
How can i do this? I really don't get it.
Thanks!