How to write a request for Yii2
I have such a request.
select page, count(*) as c from analitics group by page order by c desc limti 5
How do I do it by using Yii2? I've been trying for two hours, I can't think of anything.
$query = new ActiveQuery(); $query->select(['page' => 'page', 'c' => 'count(*)']) ->from('analitics') ->groupBy('page') ->orderBy(['c' => 'desc']) ->limit(5) ->all();
If you use ActiveRecord model, Model:find() returns a copy of ActiveQuery