您好,我正在为我们的客户群提取卷信息,并想为 SELECT 下的列 [Volume2] 编写一个子查询,以便在 Fiscal Year = 2013 时提取卷信息。由于当前编写查询,所有卷当前都包含在 Fiscal Years >= 2012 在 WHERE 子句下,但我不想在那里更改它,我想为 SELECT 下的 [Volume2] 列指定它。因此,[Volume1] 列将包括 2012 和 2013 财年的交易量,而 [Volume2] 列将仅包括 2013 年的交易量。
任何帮助表示赞赏!谢谢!
SELECT
sum([FactActualDetail].[Volume]) AS [Volume1],
sum([FactActualDetail].[Volume]) AS [Volume2],
sum([FactActualDetail].[AdjGrossMarginAmount]) AS [AdjGrossMarginAmount],
left([FactActualDetail].[SourceCustomerProductCode],7) as [Acct #],
[DimDate].[Fiscal_Year] as [Fiscal_Year],
[DimCustomer].[TerrSalesManagerName] AS [TerrSalesManagerName],
[DimCustomer].[AccountRepsalesmanName] AS [AccountRepsalesmanName]
FROM [dbo].[FactActualDetail] [FactActualDetail]
LEFT JOIN [dbo].[DimCustomer] [DimCustomer] ON ([FactActualDetail].[CustomerSK] = [DimCustomer].[CustomerSK])
LEFT JOIN [Common].[DimDate] [DimDate] ON ([FactActualDetail].[DeliveryDateSK] = [DimDate].[DateSK])
WHERE [EQMultiplier] > 0 AND [Fiscal_Year] >= 2012 AND ([SuperChannelCode] = 04 OR [SuperChannelCode] = 06 OR [SuperChannelCode] = 07) AND (substring([SourceCustomerProductCode],8,3) = 102)
GROUP BY left([FactActualDetail].[SourceCustomerProductCode],7),[TerrSalesManagerName],[AccountRepsalesmanName],[Fiscal_Year]