0

我想找到按 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 个滚动月份的平均成本。

4

1 回答 1

0

看看这个问题SQL Server: Get data for only last year

SELECT 
    AVG(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 <= DATEADD(year,-1,GETDATE())
    GROUP BY AEBill.ProviderID
于 2013-09-30T10:12:11.457 回答