Sql

Asked • 03/18/19

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

1 Expert Answer

By:

Sam Z. answered • 08/27/20

Tutor
5 (14)

Full Time Data Analyst at Amazon

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.