我的桌子:
Date Employee Status
-----------------------------
20171106 001 At work
20171107 001 Sick leave
20171108 001 At work
20171109 001 At work
20171111 001 Sick leave (A gap here)
20171112 001 Sick leave
20171115 001 At work (Another gap)
20171116 001 At work
期望的结果:
Employee Status StartDT EndDT
-------------------------------------------------------------------
001 At work Some time in the history 20171106
001 Sick leave 20171107 20171107
001 At work 20171108 20171109
001 Sick leave 20171111 20171112
001 At work 20171115 20171116
逻辑:我们按状态重新组织源表,而不是按日期。所以日期的差距并不重要,应该被忽略。
如何在 Teradata 15 中执行此操作?
注意:select min(Date), max(Date) group by employee, status;
将不起作用,因为两个“工作中”之间的状态可能会发生变化。