【LeetCode】182.寻找重复的电子邮箱 学习笔记

182.寻找重复的电子邮箱

编写一个 SQL查询,来查找名为 Person 的表中的所有重复电子邮件。


用到的表和数据SQL:

[sql]  view plain  copy
  1. Create table If Not Exists Person (Id int,Email varchar(255));  
  2. Truncate table Person;  
  3. insert into Person (Id, Email) values ('1','[email protected]');  
  4. insert into Person (Id, Email) values ('2','[email protected]');  
  5. insert into Person (Id, Email) values ('3','[email protected]');  

答案:

此题比较简单,寻找重复的数据即可,用group by Email分组后 数据个数大于1的就是重复的

[sql]  view plain  copy
  1. select Email from Person group by Email having count(Email)>1;  

查找重复的,可以直接使用group by 分组后,用count 查询其数量是否>1 ,如果是,则为重复!!

这个方法比较简单!!!

猜你喜欢

转载自blog.csdn.net/aanndd77/article/details/80770596