LeetCode题解 => 182.查找重复的电子邮箱(四十七)

查找重复的电子邮箱

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
;
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 博客之星2020 设计师:CY__ 返回首页