我有一张表hotel [hotelid,hotelname,etc]
和另一个表facilities[facilityid,facilityname]
这两个表通过表hotel_to_facilities_map[hotelid,facility_id]
因此表hotel_to_facilities_map
可能包含值
hotelid facility_id
-------------------
1 3
1 5
1 6
2 6
2 2
2 5
现在我想检索所有符合所有要求的设施的酒店
select * from hotel_to_facilities_map where facility_id IN (3,5,2)
但是当我需要OR
时,这会导致匹配为AND
表达式。
是否有针对此的解决方法或解决方案?
答案 0 :(得分:3)
select hotelid
from hotel_to_facilities_map
where facility_id in (3,5,2)
group by hotelid
having count(*) = 3