查找重复的电子邮箱
SQL结构
Create table If Not Exists Person (Id int, Email varchar(255))
Truncate table Person
insert into Person (Id, Email) values ('1', 'a@b.com')
insert into Person (Id, Email) values ('2', 'c@d.com')
insert into Person (Id, Email) values ('3', 'a@b.com')
编写一个 SQL 查询,查找 Person 表中所有重复的电子邮箱。
解法一
select Email
from Person
group by Email
having count(Email) > 1;
解法二(临时表)
select Email from
(
select Email, count(Email) as num
from Person
group by Email
) as statistic
where num > 1
;