我正在尝试返回销售特定产品的帐户列表 (SourceCustomerProductCode = 102) 并希望查看在 2013 年销售此产品的帐户,但如果他们在 2012 年销售,我希望将它们排除在我的查询(即我只想返回新客户)。我的以下查询是返回 2013 年销售此产品的帐户,但包括 2012 年销售此产品的帐户。
我知道我可以在 [CaseAndGalloneVolume] 语句中使用 case when 来在 SELECT 区域下编写此语句,但需要在 where 子句中编写此语句,因为最终我要将其他产品添加到我的表中。
谢谢你的帮助!
SELECT
sum([FactActualDetail].[CaseAndGallonVolume]) AS [CaseAndGallonVolume],
sum([FactActualDetail].[AdjGrossMarginAmount]) AS [AdjGrossMarginAmount],
left([FactActualDetail].[SourceCustomerProductCode],7) as [Acct #]
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 [Fiscal_Year] = 2013 AND [EQMultiplier] > 0 AND ([SuperChannelCode] = 04 OR [SuperChannelCode] = 06 OR [SuperChannelCode] = 07) AND (substring([SourceCustomerProductCode],8,3) = 102)
GROUP BY left([FactActualDetail].[SourceCustomerProductCode],7)