Duplicate Emails

原题: https://leetcode.com/problems/duplicate-emails/description/

题意: 编写一个SQL查询从Person表中找出所有重复的邮箱地址。

约定:(1)编写一个SQL查询从Person表中找出所有重复的邮箱地址。

例子: 

给定Person表如下:
+----+---------+
| Id | Email   |
+----+---------+
| 1  | a@b.com |
| 2  | c@d.com |
| 3  | a@b.com |
+----+---------+
应返回下表:
+---------+
| Email   |
+---------+
| a@b.com |
+---------+

标签: person、emails、邮箱地址、duplicate、email、面试
猜你感兴趣的圈子:
LeetCode交流圈
  • Bingo
    2017-08-17 17:12:31 1楼#1层
    解法一:
    SELECT Email FROM Person GROUP BY Email
    HAVING COUNT(*) > 1;
  • Bingo
    2017-08-17 17:12:45 2楼#1层
    解法二:
    SELECT DISTINCT p1.Email FROM Person p1
    JOIN Person p2 ON p1.Email = p2.Email
    WHERE p1.Id <> p2.Id;
  • 回复
隐藏