0
您好,我正在爲我們的客戶羣提取卷信息,並且希望爲SELECT下的列[Volume2]編寫一個子查詢,以便在財政年度= 2013時提取卷信息。查詢是當前編寫的,所有卷目前包含在財務年度> = 2012下的WHERE子句中,但不是在那裏更改它,而是想爲SELECT下的[Volume2]列指定它。因此[第1卷]專欄將包括2012財年和2013財年的數量,[第2卷]專欄僅包含2013年的數量。選擇下的子查詢 - 添加where子句以排除數據
任何幫助讚賞!謝謝!
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]
是的工作!謝謝! – Dale 2013-03-05 22:44:31