0

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,
]);

1 Answers1

1

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

$qr->orderBy(new \yii\db\Expression('client_id > 0 DESC, date_last DESC'));
rob006
  • 21,383
  • 5
  • 53
  • 74