using count and group by at the same select statement

Posted by Stavros on Stack Overflow See other posts from Stack Overflow or by Stavros
Published on 2010-04-27T15:15:17Z Indexed on 2010/04/28 7:33 UTC
Read the original article Hit count: 293

Filed under:
|
|

Hello, 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.

© Stack Overflow or respective owner

Related posts about sql

Related posts about count