计算销售累计

时间:2016-03-11 10:16:58

标签: sql-server sql-server-2008

enter image description here

Sales Accumulative列是错误的,我需要销售累积来添加前几天的亏损

我的代码:

SELECT
    a.Sales_Date,
    a.Sales,
    b.Sales_Target,
    (b.Sales_Target - a.Sales) Sales_Deficit,
    CASE
        WHEN DATEPART(D, Sales_Date) = 1 THEN b.sales_target
        ELSE (b.Sales_Target + (b.Sales_Target - a.Sales))
    END AS Sales_Accumulative,
    a.Port,
    b.Port_target,
    (b.Port_Target - a.Port) Port_Deficit,
    CASE
        WHEN DATEPART(D, Sales_Date) = 1 THEN b.Port_Target
        ELSE (b.Port_Target + (b.Port_Target - a.Port))
    END AS Port_Accumulative,
    a.FNB_Hybrid,
    a.Postpaid,
    a.Prepaid
FROM #MTDSales_Summary a
LEFT JOIN Sales_Port_Target b
    ON a.Sales_Date = b.Date;

0 个答案:

没有答案