首页 > 数据库技术 > 详细

mysql--查找重复的电子邮件

时间:2019-10-08 14:19:14      阅读:71      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 

解法一:(创建临时表当做子表来处理)

 

select Email from
(
  select Email, count(Email) as num
  from Person
  group by Email
) as statistic
where num > 1

 

  

解法二:(where好像只能用于原有数据表字段,聚合函数生成的字段无法配合使用)

 

select Email from Person group by Email having count(Email) > 1;

 

  

 

解法三:

select distinct a.Email from Person a, Person b where a.Email = b.Email and a.Id != b.Id 

 

  

 

 

 

 补充:

1、where后面不能跟聚合函数

2、group by 非聚合函数列  having 可以是聚合函数

 

3、where 子句的作用是在对查询结果进行分组前,将不符合where条件的行去掉,即在分组之前过滤数据,条件中不能包含聚组函数,使用where条件显示特定的行。

 

4、having 子句的作用是筛选满足条件的组,即在分组之后过滤数据,条件中经常包含聚组函数,使用having 条件显示特定的组,也可以使用多个分组标准进行分组。

 

mysql--查找重复的电子邮件

原文:https://www.cnblogs.com/vegetableDD/p/11634913.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!