查找重复的电子邮箱
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 表中所有重复的电子邮箱。
AC代码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
;
# 作者:LeetCode
重新熟悉了group by 和having