make in子句将所有项目与任何替代项匹配?

时间:2012-07-11 10:09:33

标签: sql-server-2008 join in-clause

我有一张表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表达式。

是否有针对此的解决方法或解决方案?

1 个答案:

答案 0 :(得分:3)

select hotelid
from hotel_to_facilities_map
where facility_id in (3,5,2)
group by hotelid
having count(*) = 3