数据库
首页 > 数据库> > SQL查询语句_查找重复的电子邮箱

SQL查询语句_查找重复的电子邮箱

作者:互联网

题目:
在这里插入图片描述
此题有多种解法:
1.自连查询

# Write your MySQL query statement below
select distinct(person1.Email) as Email
from Person person1,Person person2
where person1.Email=person2.Email and person1.ID!=person2.ID

2.统计查询

# Write your MySQL query statement below
select Email 
from Person 
group by Email 
having count(Email)>1

3.内连查询

# Write your MySQL query statement below
select distinct(person1.Email) 
from Person person1 
inner join Person person2 
on person1.Email = person2.Email and person1.Id != person2.Id

附:

1.dinstinct()用于取出唯一值,即去重。

2.当同时含有where子句、group by 子句 、having子句及聚集函数时,执行顺序如下:

3.where子句和having的区别是:

标签:语句,where,SQL,having,person2,person1,子句,电子邮箱,Email
来源: https://blog.csdn.net/ly17809212771/article/details/123616060