规划管理时段/会话

发布于 2024-08-26 18:59:32 字数 1622 浏览 3 评论 0原文

我在两个表上有一个计划结构,用于存储每天的可用时段和会话。

时段由一天中的时间范围定义。

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 |
+------------+-------+-------+

I have a planning structure on two tables to store available slots by day, and sessions.

A slot is defined by a range of time in the day.

CREATE TABLE slot (
  `id` int(11) NOT NULL AUTO_INCREMENT
, `date` date
, `start` time
, `end` time
);

Sessions can't overlap themselves and must be wrapped in a slot.

CREATE TABLE session (
  `id` int(11) NOT NULL AUTO_INCREMENT
, `date` date
, `start` time
, `end` time
);

I need to generate a list of available blocks of time of a certain duration, in order to create sessions.

Example:

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

I need to know which spaces of 1 hour I can use:

+------------+-------+-------+
| 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 |
+------------+-------+-------+

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

來不及說愛妳 2024-09-02 18:59:33

我认为,如果您通过算法而不是使用查询来处理此问题,您的生活将会容易得多。这可能是使用存储过程,这可能意味着在中间层编写算法。

我的建议是只在中间层进行。让数据库负责存储槽和会话,并将计算留给更适合任务的东西。

数据库用于保存知识,而不是托管业务逻辑。

I think you're life is going to be a lot easier if you approach this algorithmically rather than using a query. That could be using a sproc and that could mean writing an algorithm in the middle tier.

My recommendation is to just do it in the middle tier. Make the database responsible for storing the slots and sessions and leave the computations to something better suited to the task.

Databases are for persisting knowledge, not hosting business logic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文