user7846430
user7846430

Reputation:

Yii2 model search query to get shop open in monday & friday

I want write Yii2 model search query to get shop open in monday & friday.

below are table structure and query

shop_name  openday 
------------------------
    shop-A      Monday  
    shop-A      Tuesday
    shop-A      Wednesday
    shop-A      Thursday
    shop-A      Friday
    shop-B      Monday 
    shop-B      Tuesday


SELECT shop_name
FROM availability   WHERE openday IN ('Monday', 'Friday')
GROUP BY shop_name HAVING COUNT(*) = 2;

i want to impliment this query yii2 model search,

$query->andWhere("(`parking_availability`.`day` IN('Monday', 'Friday'))")->groupBy('parking_availability.day')->having('COUNT(*) = 2');

above query not working Please help me...

Upvotes: 0

Views: 71

Answers (1)

gmc
gmc

Reputation: 3990

Try this:

$query->andWhere(['in', 'day', ['Monday', 'Friday']])
    ->groupBy('openday')
    ->having('COUNT(shop_name) = 2');

Upvotes: 1

Related Questions