我有两个表,时隙表和配置表。我有配置表中的控制时隙表。
配置表中的记录
GuidelineId GuidelineName WeekDay ClinicNumber ProviderNumber TimeStart TimeEnd PatientsPermitted enabled
1 Guideline 1 NULL 34 NULL 6:30:00 10:59:00 2 1
2 Guideline 2 5 34 179 7:30:00 11:59:00 3 1
注意
Weekday 0 Monday
1 Tuesday,
2 Wednesday,
3 Thursday
4 Friday
5 Saturday
6 Sunday.
PatientsPermitted :No patients permitted per day
时隙表中的记录
sID, StartSlot, EndSlot, WeekDay, Valid,
1, 2020-08-01 08:30:00, 2020-08-01 09:10:00, 5, 0
2, 2020-08-01 09:10:00, 2020-08-01 09:50:00, 5, 0
3, 2020-08-01 10:40:00, 2020-08-01 11:20:00, 5, 0
4, 2020-08-01 11:20:00, 2020-08-01 12:00:00, 5, 0
5, 2020-08-01 15:20:00, 2020-08-01 16:00:00, 5, 0
9, 2020-08-01 16:00:00, 2020-08-01 16:40:00, 5, 0
7, 2020-08-06 08:30:00, 2020-08-06 09:10:00, 3, 0
8, 2020-08-06 09:10:00, 2020-08-06 09:50:00, 3, 0
9, 2020-08-06 09:50:00, 2020-08-06 10:30:00, 3, 0
10, 2020-08-06 12:00:00, 2020-08-06 12:40:00, 3, 0
11, 2020-08-06 14:00:00, 2020-08-06 14:40:00, 3, 0
12, 2020-08-06 14:40:00, 2020-08-06 15:20:00, 3, 0
13, 2020-08-11 08:30:00, 2020-08-06 09:10:00, 2, 0
14, 2020-08-11 09:10:00, 2020-08-06 09:50:00, 2, 0
15, 2020-08-11 09:50:00, 2020-08-06 10:30:00, 2, 0
16, 2020-08-11 12:00:00, 2020-08-06 12:40:00, 2, 0
17, 2020-08-11 14:00:00, 2020-08-06 14:40:00, 2, 0
18, 2020-08-11 14:40:00, 2020-08-06 15:20:00, 2, 0
Config表用于 时隙表中的控制时隙。基于配置表,有效时隙更新为true
如果应用了准则1记录
sID, StartSlot, EndSlot, WeekDay, Valid,
1, 2020-08-01 08:30:00, 2020-08-01 09:10:00, 5, 1
2, 2020-08-01 09:10:00, 2020-08-01 09:50:00, 5, 1
3, 2020-08-01 10:40:00, 2020-08-01 11:20:00, 5, 0
4, 2020-08-01 11:20:00, 2020-08-01 12:00:00, 5, 0
5, 2020-08-01 15:20:00, 2020-08-01 16:00:00, 5, 0
9, 2020-08-01 16:00:00, 2020-08-01 16:40:00, 5, 0
7, 2020-08-06 08:30:00, 2020-08-06 09:10:00, 3, 1
8, 2020-08-06 09:10:00, 2020-08-06 09:50:00, 3, 1
9, 2020-08-06 09:50:00, 2020-08-06 10:30:00, 3, 0
10, 2020-08-06 12:00:00, 2020-08-06 12:40:00, 3, 0
11, 2020-08-06 14:00:00, 2020-08-06 14:40:00, 3, 0
12, 2020-08-06 14:40:00, 2020-08-06 15:20:00, 3, 0
13, 2020-08-11 08:30:00, 2020-08-06 09:10:00, 2, 1
14, 2020-08-11 09:10:00, 2020-08-06 09:50:00, 2, 1
15, 2020-08-11 09:50:00, 2020-08-06 10:30:00, 2, 0
16, 2020-08-11 12:00:00, 2020-08-06 12:40:00, 2, 0
17, 2020-08-11 14:00:00, 2020-08-06 14:40:00, 2, 0
18, 2020-08-11 14:40:00, 2020-08-06 15:20:00, 2, 0
如果应用了准则2记录
sID, StartSlot, EndSlot, WeekDay, Valid,
1, 2020-08-01 08:30:00, 2020-08-01 09:10:00, 5, 1
2, 2020-08-01 09:10:00, 2020-08-01 09:50:00, 5, 1
3, 2020-08-01 10:40:00, 2020-08-01 11:20:00, 5, 1
4, 2020-08-01 11:20:00, 2020-08-01 12:00:00, 5, 0
5, 2020-08-01 15:20:00, 2020-08-01 16:00:00, 5, 0
9, 2020-08-01 16:00:00, 2020-08-01 16:40:00, 5, 0
7, 2020-08-06 08:30:00, 2020-08-06 09:10:00, 3, 0
8, 2020-08-06 09:10:00, 2020-08-06 09:50:00, 3, 0
9, 2020-08-06 09:50:00, 2020-08-06 10:30:00, 3, 0
10, 2020-08-06 12:00:00, 2020-08-06 12:40:00, 3, 0
11, 2020-08-06 14:00:00, 2020-08-06 14:40:00, 3, 0
12, 2020-08-06 14:40:00, 2020-08-06 15:20:00, 3, 0
13, 2020-08-11 08:30:00, 2020-08-06 09:10:00, 2, 0
14, 2020-08-11 09:10:00, 2020-08-06 09:50:00, 2, 0
15, 2020-08-11 09:50:00, 2020-08-06 10:30:00, 2, 0
16, 2020-08-11 12:00:00, 2020-08-06 12:40:00, 2, 0
17, 2020-08-11 14:00:00, 2020-08-06 14:40:00, 2, 0
18, 2020-08-11 14:40:00, 2020-08-06 15:20:00, 2, 0
以下我正在尝试的代码
UPDATE TimeSlots S INNER JOIN Guideline G ON S.WeekDay = IFNULL(G.WeekDay,S.WeekDay)
SET
S.valid=1
WHERE S.valid=0
AND
( (TIME(S.StartSlot) >= G.StartTime AND TIME(S.StartSlot) <= G.EndTime) );
我能够获得特定日期的时间段,如何实施PatientsPermitted,任何人都可以对此提供帮助 而且我也想在当前配置表中实现多个工作日,null意味着工作日从0到6整天