題目
Write a SQL query to find all duplicate emails in a table named Person.
+—-+———+
| Id | Email |
+—-+———+
| 1 | [email protected] |
| 2 | [email protected] |
| 3 | [email protected] |
+—-+———+
For example, your query should return the following for the above table:
+———+
| Email |
+———+
| [email protected] |
+———+
Note: All emails are in lowercase.
題目來源:https://leetcode.com/problems/duplicate-emails/
代碼
有哪些郵箱重複?把郵箱顯示出來。
# Write your MySQL query statement below
select Email from Person group by Email having count(Id) > 1;
注:MySQL中having關鍵字是在數據分組之後進行過濾選擇分組,而where是在分組之前用來選擇記錄。where排除的記錄不再包括在分組中。