在子句中匹配所有项或其他替代项? [英] Make in clause to match all items ot any alternative?
本文介绍了在子句中匹配所有项或其他替代项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张桌子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
现在我要检索所有与要求的所有设施匹配的酒店
now i want to retrieve all the hotels which match ALL facilities asked for
select * from hotel_to_facilities_map where facility_id IN (3,5,2)
但是当我需要AND
时,这将导致匹配作为OR
表达式.
but this will cause the match as an OR
Expression while i need AND
.
对此有任何解决方法或解决方案吗?
is there any workaround or solution for this?
推荐答案
select hotelid
from hotel_to_facilities_map
where facility_id in (3,5,2)
group by hotelid
having count(*) = 3
这篇关于在子句中匹配所有项或其他替代项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文