我想找到按 12 个月滚动平均值计算的提供商组的总成本。
SELECT
sum(AEBill.[TotalCost])
,AEEnc.ProviderID
,AEEnc.Date
INTO #TotalCostAccuteCareAE
FROM EncDetail AEEnc
INNER JOIN [EncBilling] as AEBill
ON AEBill.[SK_EncID] = AEEnc.[SK_EncID]
AND AEBill.ProviderID = AEEnc.ProviderID
WHERE AEEnc.Date <= reportDate
GROUP BY AEBill.ProviderID
此查询仅选取小于或等于报告日期的所有记录的总和。但我想要从给定月份开始的 12 个滚动月份的平均成本。