Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在MySQL中查找重复电子邮件的统计信息_Mysql_Sql - Fatal编程技术网

在MySQL中查找重复电子邮件的统计信息

在MySQL中查找重复电子邮件的统计信息,mysql,sql,Mysql,Sql,我需要查询数据库表中重复值的统计信息。例如,假设我有一个电子邮件字段,多行可以有相同的电子邮件。我知道想知道的是有多少地址被重复了多少次。换句话说:“908封邮件重复10次,1783封邮件重复9次”等等 Repeated       # of Emails 10            908 9 1783 我不需要查看实际的电子邮件地址,只需要这些统计信息 好的,我知道我有这个查询,它还检索电子邮件地址: select email_address, count(em

我需要查询数据库表中重复值的统计信息。例如,假设我有一个电子邮件字段,多行可以有相同的电子邮件。我知道想知道的是有多少地址被重复了多少次。换句话说:“908封邮件重复10次,1783封邮件重复9次”等等

Repeated       # of Emails
10             908
9              1783
我不需要查看实际的电子邮件地址,只需要这些统计信息

好的,我知道我有这个查询,它还检索电子邮件地址:

select email_address,
count(email_address) as NumberOccurrences
from table_user_info
group by email_address
having ( count(email_address) > 1 )
如何对这些结果进行分组?

聚合
COUNT()
,子查询也返回聚合
COUNT()
将提供这一点。子查询按电子邮件地址分组和计数,如
abc@example.com-10,然后外部查询根据子查询返回的重复次数进行计数和分组,丢弃实际的电子邮件地址

SELECT
  repeated,
  COUNT(*) AS numemails
FROM (
  SELECT 
     email,
     COUNT(*)
  FROM emails
  GROUP BY email
) emailcounts
select email_address,
       count(email_address) as NumberOccurrences
from table_user_info
group by email_address
having count(*) > 1