I am working with a SQLite database and I have three tables describing buildings,rooms and scheduled events.
The tables look like this:
- Buildings(ID,Name)
- Rooms(ID,BuildingID,Number)
- Events(ID,BuildingID,RoomID,Days,s_time,e_time)
So every event is associated with a building and a room. The column Days contains an integer which is a product of prime numbers corresponding to days of the week ( A value of 21 means the event occurs on Tuesday = 3 and Thursday = 7).
I am hoping to find a way to generate a report of rooms in a specific building that will be open in the next few hours, along with how long they will be open for.
Here is what I have so far:
SELECT Rooms.Number
FROM Rooms
INNER JOIN Buildings on ( Rooms.BuildingID = Buildings.ID )
WHERE
Buildings.Name = "BuildingName"
EXCEPT
SELECT Events.RoomID
FROM Events
INNER JOIN Buildings on ( Events.BuildingID = Buildings.ID )
WHERE
Buildings.Name = "BuildingName" AND
Events.days & 11 = 0 AND
time("now", "localtime" BETWEEN events.s_time AND events.e_time;
Here I find all rooms for a specific building and then I remove rooms which currently have an scheduled event in progress.
I am looking forward to all helpful tips/comments.