私はこれをMSSQLで作業しています。Continuous_d列を導出する方法を知っている人はいますか?連続する日数は、時間に関係なく、ENTER_DTのみに基づく必要があります。また、従業員が同じ日に何度も入室した場合でも、連続した1日としてカウントされます。
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;