eric
eric

Reputation: 1473

MySQL: How to group table into categories?

I have a MySQL table with a user column, and a category column. How can I write a MySQL query so that I find the number of users in each category? (I don't know the name of the categories beforehand).

Thanks!

Upvotes: 0

Views: 610

Answers (2)

Zak
Zak

Reputation: 7078

Something like:

select category, count(users) from table
group by category;

Upvotes: 1

Lukas Eder
Lukas Eder

Reputation: 220902

select category, count(user) from my_table group by category

where my_table is your table, categoryis your category column, and useris your user column

Upvotes: 3

Related Questions