Reputation: 829
I am trying to get the count of distinct value of the table for example I have below records in a table :
PK Value
1 A
2 A
3 A
4 B
5 C
6 C
7 D
8 D
9 D
10 D
11 E
12 F
Looking above there are primary key(PK)
and values, I want result like below :
Value Count
A 3
B 1
C 2
D 4
E 1
F 1
Which should do a count each of the values.
I am trying the count(value)
function but not getting the expected result, is there any other function can be used?
Upvotes: 1
Views: 3236
Reputation:
select value, count(*)
from the_table
group by value
order by value;
Upvotes: 2