Php 统计表字段中的重复值
如何计算mysql db表中任何字段中的重复值 示例:Php 统计表字段中的重复值,php,mysql,Php,Mysql,如何计算mysql db表中任何字段中的重复值 示例: id name 1 aaa 2 aaa 3 ttt 4 ccc 5 ttt 6 ccc 7 aaa 8 zzz 我怎样才能得到表中重复多少次的值呢 aaa =3 times in table ttt =2 times in table ccc =2 times in table zzz =1 times in table
id name
1 aaa
2 aaa
3 ttt
4 ccc
5 ttt
6 ccc
7 aaa
8 zzz
我怎样才能得到表中重复多少次的值呢
aaa =3 times in table
ttt =2 times in table
ccc =2 times in table
zzz =1 times in table
我认为mysql的计数是可能的,但如何使用它我不知道有人能帮上忙吗?请回答我的问题,谢谢在adv.中。您需要按
名称
列分组,然后您可以在该组上使用聚合函数,如count()
select name, count(id)
from your_table
group by name
写下面的查询以获取每个名称的计数
select name, count(name)
from your_table
group by name
或
获取特定名称的计数
select name, count(name)
from your_table
where name = "aaa"
group by name
按id分组是否会产生与其唯一id相同的结果集?他不需要按姓名分组然后进行计数吗Shere in name我想计算一些特定值,例如ma表中名称字段中aaa重复的次数。使用where子句作为特定名称或在生成的数组中,您将获得每个名称的计数。您尝试了什么?您可以将查询与问题一起发布吗?