雄辩的范围,其中有多个值

时间:2018-08-23 16:07:27

标签: php mysql laravel eloquent

我正在尝试使用laravel范围执行查询。

我有一张桌子“ hotels”,其中包含ID,名称等,每张酒店都有一张功能很多的桌子,例如:

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

1 个答案:

答案 0 :(得分:0)

每个功能需要一个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