php - 具有多个值的雄辩范围
问题描述
我正在尝试使用 laravel 范围执行查询。
我有一张带有 id、name 等的“酒店”表,还有一张表,每家酒店都有很多功能,比如:
Featute.id= 1 name=Wifi Hotel_id = 1
Featute.id= 2 name=Wifi in room Hotel_id = 1
Featute.id= 3 name=Wifi in pool Hotel_id = 1
Featute.id= 4 name=Wifi in room Hotel_id = 2
Featute.id= 5 name=Wifi in pool Hotel_id = 2
我想获得所有带有“房间内无线网络”和“游泳池内无线网络”的酒店
我需要在范围内使用哪种方法?查询会是什么样子?
我已经绑定了这个,但它返回了具有这些功能的酒店。
select `hotels`.`name` as `name`,
`hotels`.`delegation_id` as `delegation`,
`hotels`.`jpcode` as `jpcode`,
`hotels`.`iata` as `iata`,
`hotels`.`checked` as `checked`,
`hotels`.`gen_note` as `gen_note`,
`hotels`.`des_note` as `des_note`,
`hotels`.`feat_note` as `feat_note`,
`hotels`.`img_note` as `img_note`
from `hotels`
inner join `features` on `hotels`.`id` = `features`.`hotel_id`
where `features`.`name` in('Wifi in room','Wifi')
group by hotels.id
解决方案
每个功能需要一个 JOIN:
select `hotels`.`name` as `name`,
`hotels`.`delegation_id` as `delegation`,
`hotels`.`jpcode` as `jpcode`,
`hotels`.`iata` as `iata`,
`hotels`.`checked` as `checked`,
`hotels`.`gen_note` as `gen_note`,
`hotels`.`des_note` as `des_note`,
`hotels`.`feat_note` as `feat_note`,
`hotels`.`img_note` as `img_note`
from `hotels`
inner join `features` as `f1` on `hotels`.`id` = `f1`.`hotel_id`
inner join `features` as `f2` on `hotels`.`id` = `f2`.`hotel_id`
where `f1`.`name` = 'Wifi in room'
and `f2`.`name` = 'Wifi'
group by hotels.id
推荐阅读
- twig - 在 Twig 中呈现 HTML 标题元素
- python - 合并 IP 地址列上的两个 DataFrame
- c# - 通过 tcp 拆分消息
- python - 遍历字典并将数据放入 PyQt5 表中
- angular - 这个关键字的Angular 6范围在子组件中是不同的
- javascript - jquery php保留下拉值并选择复选框值
- perl - 两个模式之间的匹配和文件行
- javascript - 无法在引导程序 4 中删除类(“d-none”)
- jenkins - 如何从 SCM 中的管道刷新作业配置
- android - 分离的 React Native Expo 应用程序,使用 Feathers.js SocketIO 连接到 SSL 自签名证书的问题