3

我有一张桌子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

有什么解决方法或解决方案吗?

4

1 回答 1

3
select hotelid
from hotel_to_facilities_map
where facility_id in (3,5,2)
group by hotelid
having count(*) = 3
于 2012-07-11T10:19:42.630 回答