我正在尝试将拥有特定商店的购物中心归为“某些商店”,将“其他所有商店”归为一组,但我为拥有该商店的每个购物中心返回两个条目。一次使用“某些商店”,一次使用“所有其他商店”,因为它既包含特定商店也包含其他商店。我如何让我的group by子句只返回每个购物中心一次?
SELECT t5.mall_id
,t5.mall_name
,t5.sear_mall
FROM (
SELECT DISTINCT t1.mall_id
,t2.mall_name
,CASE
WHEN NPDOutlet LIKE '%Sear%'
THEN 'Sear''s'
ELSE 'All Other Anchors'
END AS sear_mall
FROM dbo.combined_stores AS t1
LEFT OUTER JOIN (
SELECT id
,'Outlet Mall' AS Source
,mall_name
FROM dbo.outbound_malls
UNION ALL
SELECT ID
,'Traditional Mall' AS Source
,Mall_Title
FROM dbo.malls_zip_state
) AS t2 ON t1.mall_id = t2.id
LEFT OUTER JOIN dbo.New_Mapping AS t3 ON t1.id = t3.id
) AS t5
GROUP BY mall_id
,mall_name
,sear_mall