我使用此查询来计算年份。但是花了太多时间才能执行。
如何优化它?
SELECT T.[Sales_Organization],
T.[CD_DossierMagnitude],
T.[DS_DossierMagnitude],
T.[Sales_Product_Name_N3],
T.[Sales_Product_Name_N2],
T.[Sales_Product_Name_N1],
T.[Market_Segment_Name_N2],
T1.*
FROM stg.Fact_EPV_SEFPRO_DC T
CROSS APPLY (SELECT SUM([QTY]) AS QTY_YTD,
SUM([QTY_UoM]) AS QTY_UoM_YTD,
SUM([PNV_LC]) AS PNV_LC_YTD,
SUM([Vmvu]) AS Vmvu_YTD
FROM stg.Fact_DC
WHERE [Delivery_Year] = T.[Delivery_Year]
AND Delivery_month <= t.Delivery_month
AND Sales_Organization = T.Sales_Organization
AND Sales_Product_Name_N3 = T.Sales_Product_Name_N3
AND Sales_Product_Name_N2 = T.Sales_Product_Name_N2
AND Sales_Product_Name_N1 = T.Sales_Product_Name_N1
AND Market_Segment_Name_N2 = T.Market_Segment_Name_N2
AND Market_Grp = T.Market_Grp
AND Product_Name_SOA = T.Product_Name_SOA
AND Doc_Currency = T.Doc_Currency) t1