Answer the question
In order to leave comments, you need to log in
How to translate sql query from group by to active record?
There is a working request
SELECT `u_id` , COUNT( `u_id` ) AS `rating`
FROM `u_h`
GROUP BY `u_id`
$query = U_h::find();
$u_rating = $query
->select(['u_id'], [count('u_id') as 'rating'])
->from('u_h')
->groupBy('u_id')
->all();
Answer the question
In order to leave comments, you need to log in
$query = U_h::find()->select(['u_id', 'rating' => 'COUNT(u_id)'])->from('u__H')->groupBy('u_id')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question