【MySQL】【leetcode】 Duplicate Emails解题报告

来源:互联网 发布:苏州聚合数据 编辑:程序博客网 时间:2024/06/04 18:52

题目

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

+—-+———+
| Id | Email |
+—-+———+
| 1 | a@b.com |
| 2 | c@d.com |
| 3 | a@b.com |
+—-+———+
For example, your query should return the following for the above table:

+———+
| Email |
+———+
| a@b.com |
+———+
Note: All emails are in lowercase.
题目来源:https://leetcode.com/problems/duplicate-emails/

代码

有哪些邮箱重复?把邮箱显示出来。

# Write your MySQL query statement belowselect Email from Person group by Email having count(Id) > 1;

注:MySQL中having关键字是在数据分组之后进行过滤选择分组,而where是在分组之前用来选择记录。where排除的记录不再包括在分组中。

0 0
原创粉丝点击