您当前的位置: 首页 >  leetcode

孑渡

暂无认证

  • 2浏览

    0关注

    178博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Leetcode】简单题:查找重复的电子邮箱

孑渡 发布时间:2022-04-15 14:20:40 ,浏览量:2

查找重复的电子邮箱

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

关注
打赏
1663211900
查看更多评论
立即登录/注册

微信扫码登录

0.1531s