使子句,匹配所有项目加时赛任何替代?(Make in clause to match all ite

2019-07-30 09:05发布

我有一个表hotel [hotelid,hotelname,etc]

而另一台facilities[facilityid,facilityname]

这些2代表通过表链接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

有没有解决方法或解决方案呢?

Answer 1:

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


文章来源: Make in clause to match all items ot any alternative?