【MySQL】【leetcode】 Duplicate Emails解題報告

題目

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排除的記錄不再包括在分組中。

發佈了100 篇原創文章 · 獲贊 21 · 訪問量 35萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章