MySQL - 返回不同的行和重复的计数

时间:2022-09-23 12:28:49

MySQL isn't my strong suit, can someone recommend an efficient query for pulling all distinct values from a column and counting all duplicates of each distinct value?

MySQL不是我的强项,有人可以推荐一个有效的查询来从列中提取所有不同的值并计算每个不同值的所有重复项吗?

So for example the following table

例如,下表

s_ip
---------   
10.1.25.4
10.8.25.8
10.1.25.4
10.1.25.4
10.8.25.8
10.1.48.1
10.1.25.4

Would return

s_ip      | Count
----------|------
10.1.25.4 | 4
10.8.25.8 | 2
10.1.48.1 | 1

Thanks in advance

提前致谢

2 个解决方案

#1


1  

SELECT s_ip , COUNT(*) as count FROM table_name GROUP BY (s_ip)

#2


0  

select 
s_ip, count(*) as `count`
from table
group by s_ip

DEMO

#1


1  

SELECT s_ip , COUNT(*) as count FROM table_name GROUP BY (s_ip)

#2


0  

select 
s_ip, count(*) as `count`
from table
group by s_ip

DEMO