이전날자와 비교하여 날짜차이 찾기

빠진이빨찾기II
참조 : http://www.gooper.com/ss/index.php?mid=tnt_db&sort_index=regdate&order_type=desc&comment_srl=3990&document_srl=1764

. 자 ~~ 응용

WITH T_EPA AS
(
SELECT
ROW_NUMBER() OVER (ORDER BY ErPatCalcYmd) AS RowNum
, ErPatCalcYmd
FROM MP_ErPatDailyCalc WITH(NOLOCK)
GROUP BY ErPatCalcYmd
)
, T_EPB AS
(
SELECT
A.RowNum
, A.ErPatCalcYmd
, B.ErPatCalcYmd AS BeErPatCalcYmd
, DATEDIFF(DD,CONVERT(DATETIME, B.ErPatCalcYmd), CONVERT(DATETIME, A.ErPatCalcYmd) ) AS DaysCout
FROM T_EPA AS A
LEFT OUTER JOIN T_EPA AS B
ON A.RowNum = B.RowNum+1
)
SELECT * FROM T_EPB
WHERE DaysCout > 1

Posted by 말없제이
,