如何对单个 table 中的多行进行分组并获取给定范围内的所有记录

how to group multiple rows from single table and get all record within given range

我想要我的旅馆 table 给定价格范围内的所有旅馆。 价格存储在四个不同的行中,如一股价格、两股价格、三股价格、更多股价格,

public function actionNearbyHostel($min,$max,$types,$lat,$long){   
    $latitude = $lat;
    $longitude = $long;
    $type = $types;
    $max_price = (int)$max;
    $min_price = (int)$min;
    $hostels = Hostels::find ()->select("*,(6371 * 
        acos(cos(radians({$latitude}))* 
        cos(radians(`lat`)) * cos(radians(`log`) - radians({$longitude})) + 
        sin(radians({$latitude})) * sin(radians(`lat`)))) AS distance")
            ->having("distance<:distance")
            ->addParams([ 
                ':distance' => 5 
            ])->where([
                'status' => Hostels::ACTIVE,
                'type' => $type
            ])->andWhere(['between','price_one_share',$min_price,$max_price])
    ->all();
    return $this->render('filterhostel',[
        'hostels' => $hostels,
    ]);
} 

这是我已经写过的动作

andWhere(['between','price_one_share',$min_price,$max_price])

像这样,我想包括剩余的三行并得到我的结果。

这是我的 table 行图像 http://www.clipular.com/posts/4991398571671552?k=Lud1W4LGJe5hSxOsl2ao7VOGguI

经过一番功课,我找到了答案

 public function actionNearbyHostel($min,$max,$types,$lat,$long){   
    $latitude = $lat;
    $longitude = $long;
    $type = $types;
    $max_price = (int)$max;
    $min_price = (int)$min;
    $hostels = Hostels::find ()->select("*,(6371 * acos(cos(radians({$latitude}))* 
    cos(radians(`lat`)) * cos(radians(`log`) - radians({$longitude})) + 
    sin(radians({$latitude})) * sin(radians(`lat`)))) AS distance")
    ->having("distance<:distance")
    ->addParams([ 
    ':distance' => 5 
    ])->where([
    'status' => Hostels::ACTIVE,
    'type' => $type
    ])->andWhere(['or',
    ['between','price_one_share',$min_price,$max_price],
    ['between','price_two_share',$min_price,$max_price],
    ['between','price_three_share',$min_price,$max_price],
    ['between','price_more_share',$min_price,$max_price]
    ])
    ->all();
    return $this->render('filterhostel',[
        'hostels' => $hostels,
    ]);
}