我在两张桌子上有一个计划结构,可以按天存储可用的时段和会话。
时隙由一天中的时间范围定义。
CREATE TABLE slot (
`id` int(11) NOT NULL AUTO_INCREMENT
, `date` date
, `start` time
, `end` time
);
会话不能重叠,必须封装在槽中。
CREATE TABLE session (
`id` int(11) NOT NULL AUTO_INCREMENT
, `date` date
, `start` time
, `end` time
);
我需要生成一个特定时间段的可用时间块列表,以便创建会话。
例子:
INSERT INTO slot
(date, start, end)
VALUES
("2010-01-01", "10:00", "19:00")
, ("2010-01-02", "10:00", "15:00")
, ("2010-01-02", "16:00", "20:30")
;
INSERT INTO slot
(date, start, end)
VALUES
("2010-01-01", "10:00", "19:00")
, ("2010-01-02", "10:00", "15:00")
, ("2010-01-02", "16:00", "20:30")
;
2010-01-01
<##><####> <- Sessions
------------------------------------ <- Slots
10 11 12 13 14 15 16 17 18 19 20
2010-01-02
<##########> <########> <- Sessions
-------------------- ------------------ <- Slots
10 11 12 13 14 15 16 17 18 19 20
我需要知道我可以使用哪一个1小时的空间:
+------------+-------+-------+
| date | start | end |
+------------+-------+-------+
| 2010-01-01 | 13:00 | 14:00 |
| 2010-01-01 | 14:00 | 15:00 |
| 2010-01-01 | 15:00 | 16:00 |
| 2010-01-01 | 16:00 | 17:00 |
| 2010-01-01 | 17:00 | 18:00 |
| 2010-01-01 | 18:00 | 19:00 |
| 2010-01-02 | 10:00 | 11:00 |
| 2010-01-02 | 11:00 | 12:00 |
| 2010-01-02 | 16:00 | 17:00 |
+------------+-------+-------+