Andreykin Sergey
Andreykin Sergey

Reputation: 113

How to add comparison in order condition of Yii2 query builder?

So, I have SQL string with order by part like:

ORDER BY
    client_id>0 DESC,
    date_last DESC

I want to have similar condition in Query builder. What i need to add? (especially for "client_id>0")

$qr->orderBy([
    'client_id' => SORT_DESC,
    'date_last' => SORT_DESC,
]);

Upvotes: 0

Views: 375

Answers (1)

rob006
rob006

Reputation: 22174

You can use yii\db\Expression to pass raw SQL statement:

$qr->orderBy(new \yii\db\Expression('client_id > 0 DESC, date_last DESC'));

Upvotes: 1

Related Questions