$listsArray = (new yii\db\Query()) ->select('*') ->from('tablea AS a') ->leftJoin('tableb AS b', 'a.consultant = b.consultant') ->where("a.begin_at_plan < $endTime") ->orderBy(["FIELD(a.status,1,0,3,2)"=>true, 'a.begin_at_plan'=>SORT_DESC]); var_dump($listsArray->createCommand()->getRawSql());die;
// ->all();