How to use count and group by at the same select statement

I have an sql select query that has a group by.
I want to count all the records after the group by statement.
Is there a way for this directly from sql?
For example, having a table with users I want to select the different towns and the total number of users

select town, count(*) from user
group by town

I want to have a column with all the towns and another with the number of users in all rows.

An example of the result for having 3 towns and 58 users in total is :

Town         Count
Copenhagen   58
NewYork      58
Athens       58

11 Answers
11

Leave a Comment