-
Bingo解法一:
SELECT Email FROM Person GROUP BY Email HAVING COUNT(*) > 1;
-
Bingo解法二:
SELECT DISTINCT p1.Email FROM Person p1 JOIN Person p2 ON p1.Email = p2.Email WHERE p1.Id <> p2.Id;
-
原题: 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 |
+---------+
SELECT Email FROM Person GROUP BY Email HAVING COUNT(*) > 1;
SELECT DISTINCT p1.Email FROM Person p1 JOIN Person p2 ON p1.Email = p2.Email WHERE p1.Id <> p2.Id;