这
group by将工作:
select ItemIdfrom Item_has_categorygroup by ItemIdhaving sum(case when CategoryId = 1 then 1 end) = 1 or sum(case when CategoryId = 2 then 1 end) = 1 andsum(case when CategoryId = 3 then 1 end) = 1

这
group by将工作:
select ItemIdfrom Item_has_categorygroup by ItemIdhaving sum(case when CategoryId = 1 then 1 end) = 1 or sum(case when CategoryId = 2 then 1 end) = 1 andsum(case when CategoryId = 3 then 1 end) = 1