Answer the question
In order to leave comments, you need to log in
How to count quantity with ActiveRecord?
Good afternoon.
How to count the number of cities in a table? `id`,`user`,`country_id`,`city_id`
How to get just the number of records - understandable <?= User::find()->count()?>
And how to calculate the number of cities a user has?
I don’t understand the query itself by counting unique cities
Answer the question
In order to leave comments, you need to log in
1. SELECT COUNT(DISTINCT `city_id`) AS `city_count` FROM `user_table`;
2. SELECT `user`, COUNT(DISTINCT `city_id`) AS `city_count` FROM `user_table` GROUP BY `user`;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question