Reputation: 443
There is a column that can have several values. I want to select a count of how many times each distinct value occurs in the entire set. I feel like there's probably an obvious solution but it's eluding me. I'll show input & expected output, hopefully it's obvious enough that you'll understand.
This is example data:
|-------|
| class |
|-------|
| 5 |
| 5 |
| 12 |
| 4 |
| 12 |
|-------|
This is the output I'm trying to get:
|-------|-------|
| class | count |
|-------|-------|
| 5 | 2 |
| 12 | 2 |
| 4 | 1 |
|-------|-------|
Upvotes: 0
Views: 992
Reputation: 1793
Please try this
SELECT class , count( class ) AS COUNT FROM `tble` GROUP BY class
Upvotes: 0
Reputation: 2640
Make Count as column
select class, count(1) as Count
from table
group by class
Upvotes: 0