Answer the question
In order to leave comments, you need to log in
How to count how many of each id is in the database?
There is a database orders. In which, for example, the fields id caregory_id, etc.
I need to count how many orders for a certain category. That is, how many tempers by category_id = 1, category_id = 2, and so on and take the 5 largest.
How to conjure such a request?
Answer the question
In order to leave comments, you need to log in
COUNT() + GROUP BY
https://www.w3resource.com/sql/aggregate-functions...
Yii::$app->db->createCommand('select caregory_id, count(*) from table_name group by caregory_id order by count(*) desc limit 5')->queryAll();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question