查找 Person 表中所有重复的电子邮箱

编写一个 SQL 查询,查找 Person 表中所有重复的电子邮箱。
|id| email |
|1|1350908@qq.com|
|2| 2345678@qq.com|
|3|2345678@qq.com |
执行完sql应该展示的结果为
|email|
|2345678@qq.com|
注意 where>group by>having>order by
方法一 groupBy+having
1 gruopbyby对数据按照哪个字段进行分组
可以实现把重复的分组
2 此题只要重复的因此需要组的个数大于1
sql
`select emailfrom persongroup by email
having count(email)>1
方法二 自连接+去重
select distinct p1.email
from person p1,person p2
where p1.id !=p2.id and p1.email=p2.email
方法三 临时表
select r.email
from (select count(1) n, email from person group by email) r
where n>1

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值