我有各种活动的记录,这些活动的开始和结束时间可能跨越数小时,例如 12:00 = 13:30。我需要将时间分配到小时,以便将时间分配为该活动的 12:00 - 1 小时、13:00、00:30。实现这一目标的最佳方法是什么?
这是创建表、插入和预期结果。需要帮助请叫我。谢谢!
CREATE TABLE Z_SCHED_ACTIVITY
(
SCHED_ACTIVITY_ID decimal(38),
STARTTIME timestamp,
ENDTIME timestamp,
ACTIVITY_ID decimal(38),
EMPLOYEE_ID decimal(38),
SHIFT_ID decimal(38)
);
插入:
INSERT INTO Z_SCHED_ACTIVITY VALUES (16452556,{ts '2013-04-11 01:00:00.0'},{ts '2013-04-11 02:00:00.0'},-4107,5217,252849);
INSERT INTO Z_SCHED_ACTIVITY VALUES (16456677,{ts '2013-04-11 05:30:00.0'},{ts '2013-04-11 05:45:00.0'},-4104,1878,249440);
INSERT INTO Z_SCHED_ACTIVITY VALUES (16457993,{ts '2013-04-11 03:52:00.0'},{ts '2013-04-11 04:07:00.0'},-4104,5217,252849);
INSERT INTO Z_SCHED_ACTIVITY VALUES (16613742,{ts '2013-04-11 08:00:00.0'},{ts '2013-04-11 09:00:00.0'},-4107,1878,249440);
INSERT INTO Z_SCHED_ACTIVITY VALUES (16613744,{ts '2013-04-11 10:30:00.0'},{ts '2013-04-11 10:45:00.0'},-4104,1878,249440);
INSERT INTO Z_SCHED_ACTIVITY VALUES (16613744,{ts '2013-04-10 23:45.00.0'},{ts '2013-04-11 00:45:00.0'},-4104,1878,249440);
EXPECTED RESULT
Shift ID EmployeeID hour start Sched Time Activity
249440 1878 04/10/2013 23:00:00 15 -4104
249440 1878 04/11/2013 00:00:00 45 -4104
249440 1878 04/11/2013 05:00:00 15 -4104
249440 1878 04/11/2013 08:00:00 60 -4107
249440 1878 04/11/2013 10:00:00 15 -4104
252849 5217 04/11/2013 01:00:00 60 -4107
252849 5217 04/11/2013 03:00:00 8 -4104
252849 5217 04/11/2013 04:00:00 7 -4104