这group by
将工作:
select ItemId
from Item_has_category
group by
ItemId
having 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
结合AND / OR的MySQL多对多条件
这group by
将工作:
select ItemId
from Item_has_category
group by
ItemId
having 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