Answer the question
In order to leave comments, you need to log in
Why doesn't Count(*) as work?
This is how I write
$top=Watch::find()
->select(['fl_serial.*,fl_watch.*,COUNT(fl_watch.active=1) AS total_count'])
->joinWith('serial','fl_watch.id_serial=serial.id')
->groupBy('fl_watch.id_serial')
->orderBy(['total_count'=>SORT_DESC])
->limit(10)
->all();
foreach($top as $post){
$posts[]=$post->total_count;}
Answer the question
In order to leave comments, you need to log in
Apparently, there is no total_count property in the Watch model, so it needs to be added:
public $total_count;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question