此查询返回给我特定日期占用的房间 #077 的列表;如何反转此查询并仅显示 07:00:00 到 22:00:00 之间不在数据库中的时间?(间隔 30 分钟),每节课只需要 1 小时 30 分钟
select
*
from
(select
rooms.id, rooms.number, rooms.building, rooms.capacity
from
rooms) R1,
(select
exam_schedules.room_id,
exam_schedules.day,
exam_schedules.start_time,
exam_schedules.end_time
from
exam_schedules) R2
where
R2.room_id = R1.id and R2.day = 'tuesday' and R1.number = '077'
这是结果:
ID number Bulding Capacity room_id day start_time end_time
1 077 ACT 12 1 tuesday 10:30:00 12:00:00
但我需要下面显示的结果(这几乎显示了考试不占用的可用时间,并且不能被其他考试占用,因为它可能会导致安排问题:例如,如果考试已经安排在 10.30,只有应该显示 9.00(不是 9.30),因为如果显示 9.30 - 它会导致冲突:9.30+1.30 = 11.00 - 但我已经为这个房间安排了 10.30-12.00)
1 077 ACT 12 1 tuesday 07:00:00
1 077 ACT 12 1 tuesday 07:30:00
1 077 ACT 12 1 tuesday 08:00:00
1 077 ACT 12 1 tuesday 08:30:00
1 077 ACT 12 1 tuesday 09:00:00
//note that time frame from 9.30-10.30 is not available since there is a class at 10.30 scheduled already
//note that time period 10.30-<12.00 not shown since class is already scheduled for this timeframe 10.30-12.00
1 077 ACT 12 1 tuesday 12:00:00
1 077 ACT 12 1 tuesday 12:30:00
1 077 ACT 12 1 tuesday 13:00:00
1 077 ACT 12 1 tuesday 13:30:00
1 077 ACT 12 1 tuesday 14:00:00
1 077 ACT 12 1 tuesday 14:30:00
1 077 ACT 12 1 tuesday 15:00:00
1 077 ACT 12 1 tuesday 15:30:00
1 077 ACT 12 1 tuesday 16:00:00
1 077 ACT 12 1 tuesday 16:30:00
1 077 ACT 12 1 tuesday 17:00:00
1 077 ACT 12 1 tuesday 17:30:00
1 077 ACT 12 1 tuesday 18:00:00
1 077 ACT 12 1 tuesday 18:30:00
1 077 ACT 12 1 tuesday 19:00:00
1 077 ACT 12 1 tuesday 19:30:00
1 077 ACT 12 1 tuesday 20:00:00
1 077 ACT 12 1 tuesday 20:30:00
1 077 ACT 12 1 tuesday 21:00:00
1 077 ACT 12 1 tuesday 21:30:00
1 077 ACT 12 1 tuesday 22:00:00
数据库中不存在包含所有可能时间范围的表。我可以将其编码到查询中吗?