每次我更新数据时,我都希望它只反映最近6个月的数据。以下是我当前的查询。有人可以帮我吗?
SELECT ar.[Report Date]
,ar.Facility
,SUM (ar.[0-30]) AS [0-30]
,SUM (ar.[31-60]) AS [31-60]
,SUM (ar.[61-90]) AS [61-90]
,SUM (ar.[91-120]) AS [91-120]
,SUM (ar.[120+]) AS [120+]
FROM DBO.ARByPayer AS ar
WHERE ar.[Current Financial Class] <> 'Lien'
GROUP BY ar.Facility, ar.[Report Date]
ORDER BY ar. [Report Date]
答案 0 :(得分:1)
如果我正确理解了您的要求,则需要将其添加到where子句中:
and ar.[Report Date] > DATEADD(m, -6, GetDate())
答案 1 :(得分:0)
您可以将此子句添加到WHERE
部分:
DATEADD(d, 180, ar.[Report Date]) > getdate()