$char=new Expression("*, to_char(".News::tableName().".create_at,'MM') as mouth");
return News::find()->select($char)->where(['top'=>true])->orderBy(['mouth'=>SORT_ASC])->all();
[
{
"id": 1,
"title": "Title",
"description": "Title",
"create_at": "2019-07-04 09:35:19",
"update_at": "2019-07-04 09:35:19",
"top": true
}
]
query = Yii::$app->db->createCommand("SELECT *, DATE_FORMAT(".Cars::tableName().".car_created_date,'%m') as mouth From `cars` WHERE `status` = 3 LIMIT 2")->queryAll();