[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.

答案:

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

參考:

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


這裡的資訊對您有用嗎?歡迎斗內給我