[MySQL][LeetCode][Easy] 182. Duplicate Emails

心得:

題目要求找出Email重複的資料並Show出來,這裡要注意的是沒辦法使用WHERE而必須使用HAVING,因為WHEREGROUP BY前面,HAVINGGROUP BY後面。

問題:

Write a SQL query to find all duplicate emails in a table named Person.
答案:

1
2
3
4
5

SELECT Email
FROM Person
GROUP BY Email
HAVING COUNT(Email) > 1

參考:

  1. SQL語法中WHERE與HAVING有何差異?