1

Using Case I trying to find the group by count by range, The query that I have written like:

$this->find()
        ->select([
            'count' => $this->find()->func()->count('*')
        ])
        ->where(function ($exp, $q) {
                return $exp->addCase(
                    [
                        $q->newExpr()->lt('price', 500),
                        $q->newExpr()->between('price', 501, 1000),
                        $q->newExpr()->between('price', 1001, 2000),
                        $q->newExpr()->gte('price', 2001),
                    ],
                    ['0-500',  '501-1000', '1001-2000','2001>'],

                );
            }
        )
        ->andWhere(['Products.product_category_id' => 3])
        ->group(['then'])
    ;

My expected output:

0-500     20
501-1000  23
1001-2000 21
2001>     30

How could I apply this range in group by?

Abu Sayed
  • 75
  • 7

0 Answers0