如何编写此查询,以使这些段不互斥?似乎在“ DMA”存储桶中找到一条记录后,该记录便被排除在其他文件中。我需要查看何时在所有文件中找到记录。
SELECT LastName
,Address1
,Address2
,City
,Zip
,DealerRegion
,SuppressionReason
,max(CASE
WHEN [File] = 'DMA'
THEN 1
ELSE 0
END) AS InDMAFile
,max(CASE
WHEN [File] = 'VEH'
THEN 1
ELSE 0
END) AS InVEHFile
,max(CASE
WHEN [File] = 'LST'
THEN 1
ELSE 0
END) AS InLSTFile
,max(CASE
WHEN [File] = 'V12'
THEN 1
ELSE 0
END) AS InV12File
,max(CASE
WHEN emailaddress IS NOT NULL
THEN 1
ELSE 0
END) AS HasEmail
,max(CASE
WHEN Emailable = 'Y'
THEN 1
ELSE 0
END) AS CanEmail
FROM mytable
WHERE SuppressionReason IS NULL
GROUP BY LastName
,Address1
,Address2
,City
,Zip
,DealerRegion
,SuppressionReason