我在 MS SQL 上工作。任何人都知道如何导出 Continuous_d 列?连续的天数应该完全基于 ENTER_DT 而不管时间。如果一个员工在同一天多次进入,它仍然被计算为连续一天。
PASS_M| ENTER_DT................|CONSECUTIVE_D
Boo K K 5/1/2012 11:55:00 PM 1
Boo K K 5/2/2012 11:30:00 PM 2
Boo K K 5/4/2012 10:30:00 AM 1
LIAW S 4/30/2012 11:48:52 PM 1
LIAW S 5/1/2012 00:11:07 AM 2
LIAW S 5/1/2012 12:32:07 AM 2
LIAW S 5/1/2012 4:42:02 AM 2
LIAW S 5/2/2012 1:10:09 AM 3
LIAW S 5/2/2012 1:43:06 AM 3
LIAW S 5/4/2012 2:17:47 AM 1
更新:这是我尝试过的:
SELECT PASS_M, ENTRY_DT, DATEDIFF(D, MIN(ENTRY_DT) OVER (PARTITION BY PASS_M), ENTRY_DT) + 1 AS CONSECTUTIVE_DAYS
INTO TEMP_TARGET
FROM TEMP_5
ORDER BY PASS_M, ENTRY_DT;