마지막 지불 상태가 6 개월 전인 계정의 레코드를 가져 오는 코드가 필요합니다. 하지만 내 DateDiff가 작동하지 않는 이유는 잘 모르겠습니다. 지금까지SQL Server 2014에서 6 개월 이상 된 결과를 얻으려면 어떻게해야합니까?
내 코드 :
SELECT A.[AccountId]
,[AccountNumber]
,[AccountTypeId]
,[AccountStatusId]
,[CurrentBalance]
,[PaymentStatusID]
,D.Last_Change
FROM [Account] A
INNER JOIN (
SELECT AccountId
,MAX(Created) Last_Change
FROM PaymentStatusHistory
WHERE ToPaymentStatusID IN (1,2,11)
GROUP BY AccountId
) D
ON A.AccountID = D.AccountId
WHERE PaymentStatusID IN (1,2,11)
AND AccountStatusId IN (1,2)
--AND DATEDIFF (DAY, GETDATE(), D.Last_Change) > 180 --Need THIS line corrected.
ORDER BY CurrentBalance DESC, AccountNumber
"작동하지 않는다"는 것은 무엇을 의미합니까? 오류가 있습니까? 아니면 결과가 예상과 다른가요? – cddt