3. Find Anagram Mappings

Title:

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

Example :

case:

+----+---------+
| Id | Email   |
+----+---------+
| 1  | [email protected] |
| 2  | [email protected] |
| 3  | [email protected] |
+----+---------+

return:
+---------+
| Email   |
+---------+
| [email protected] |
+---------+

Note:

 All Email is lowercase letters.

Analysis of Title:

None

Test case:

{"headers": {"Person": ["Id", "Email"]}, "rows": {"Person": [[1, "[email protected]"], [2, "[email protected]"], [3, "[email protected]"]]}}

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)

猜你喜欢

转载自www.cnblogs.com/sxuer/p/10628772.html