SQL获取可能的间隔

时间:2018-11-09 14:21:16

标签: sql azure-sql-database

我需要让空闲时间变慢,以便在两个日期之间的所有日期都可以进行给定的任务分配。

输入:     作业时间长度(例如120分钟)     用户身份     首次可能的日期     上次可能的日期

Result:
List of all time time slows where is possible for him to do work, half our interval as in 07.00, 07.30, 08.00, 08.30, 09.00, 09.30 ....
After assignment end User need 30 min for trasnportation:






  Table Users
    --------------------------
    UserId | Earliest | Latest
     23259 | 7.30     | 15.30
     1143  | 8.30     | 16.30
     203   | 7.00     | 16300

    Table Booked
    --------------------------
    UserId | EventStartDate              | EventEndDate
     23259 | 2018-11-09 07:30:00.000     | 2018-11-09 09:00:00.000
     1143  | 2018-11-09 07:00:00.000     | 2018-11-09 16:00:00.000
     203   | 2018-11-14 08:00:00.000     | 2018-11-15 09:00:00.000
     203   | 2018-11-14 10:00:00.000     | 2018-11-15 12:00:00.000
     203   | 2018-11-14 15:00:00.000     | 2018-11-15 15:30:00.000
     203   | 2018-11-14 16:00:00.000     | 2018-11-15 16:30:00.000


Result temp table:
UserId | EventStartDate
 23259 | 2018-11-09 10:00:00.000
 23259 | 2018-11-09 10:30:00.000
 23259 | 2018-11-09 11:00:00.000
 23259 | 2018-11-09 11:30:00.000
 23259 | 2018-11-09 12:00:00.000
 23259 | 2018-11-09 12:30:00.000
 23259 | 2018-11-09 13:00:00.000
 23259 | 2018-11-09 13:30:00.000
 23259 | 2018-11-10 07:30:00.000
.
.
.
23259 | 2018-11-15 13.30:00:00.000
 23259 | 2018-11-09 10:00:00.000
 23259 | 2018-11-09 10:30:00.000
 23259 | 2018-11-09 11:00:00.000
 23259 | 2018-11-09 11:30:00.000
 23259 | 2018-11-09 12:00:00.000
 23259 | 2018-11-09 12:30:00.000
 23259 | 2018-11-09 13:00:00.000
 23259 | 2018-11-09 13:30:00.000
 23259 | 2018-11-10 07:30:00.000
.
.
.
23259 | 2018-11-15 13.30:00:00.000
 1143  | 2018-11-10 09 10:00:00.000
 1143  | 2018-11-10 10:30:00.000
 1143  | 2018-11-10 11:00:00.000
 1143  | 2018-11-10 11:30:00.000
 1143  | 2018-11-10 12:00:00.000
 1143  | 2018-11-10 12:30:00.000
 1143  | 2018-11-10 13:00:00.000
 1143  | 2018-11-10 13:30:00.000
 1143  | 2018-11-11 07:30:00.000

。 。 。 1143 | 2018-11-15 13.30:00:00.000

如何使用SQL做到这一点? (版本Microsoft SQL Azure)

0 个答案:

没有答案