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;