rakesh_parashar
rakesh_parashar

Reputation: 829

SQL: Get count of distinct values of the table

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

Answers (2)

user330315
user330315

Reputation:

select value, count(*)
from the_table
group by value
order by value;

Upvotes: 2

Matt
Matt

Reputation: 15061

SELECT Value, count(Value) AS Count,
FROM table
Group BY Value

Upvotes: 1

Related Questions