3. Find Anagram Mappings

Title:

Write an SQL query to find all duplicate e-mails in the Person table.

Example :

case:

+----+---------+
| Id | Email   |
+----+---------+
| 1  | a@b.com |
| 2  | c@d.com |
| 3  | a@b.com |
+----+---------+

return:
+---------+
| Email   |
+---------+
| a@b.com |
+---------+

Note:

 All Email is lowercase letters.

Analysis of Title:

None

Test case:

{"headers": {"Person": ["Id", "Email"]}, "rows": {"Person": [[1, "a@b.com"], [2, "c@d.com"], [3, "a@b.com"]]}}

MySQL:

select Email from Person group by Email having count(*)>1;

Analysis of Code:

We need to return(or so-called select) Emali non-repetitive.

The first key is 'all duplicate', so we need to 'group by'.

The second key is 'repeated', so it means the count is greater than 1, so we select count(*>1)

原文地址:https://www.cnblogs.com/sxuer/p/10628772.html