[英]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 : 看上面有主键
(PK)
和值,我想要如下结果:
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? 我正在尝试
count(value)
函数但没有得到预期的结果,是否可以使用任何其他函数?
select value, count(*)
from the_table
group by value
order by value;
SELECT Value, count(Value) AS Count,
FROM table
Group BY Value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.