# Write your MySQL query statement below
182. 查找重复的电子邮箱
编写一个 SQL 查询,查找 Person
表中所有重复的电子邮箱。
示例:
+----+---------+ | Id | Email | +----+---------+ | 1 | a@b.com | | 2 | c@d.com | | 3 | a@b.com | +----+---------+
根据以上输入,你的查询应返回以下结果:
+---------+ | Email | +---------+ | a@b.com | +---------+
说明:所有电子邮箱都是小写字母。
原站题解
pythondata 解法, 执行用时: 348 ms, 内存消耗: 59.9 MB, 提交时间: 2023-09-17 10:58:19
import pandas as pd def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame: df = person.groupby('email').size().reset_index(name='count') return df[df['count'] > 1][['email']] def duplicate_emails2(person: pd.DataFrame) -> pd.DataFrame: return person.groupby('email').count().reset_index() \ .query('id > 1')[['email']].rename(columns={'email': 'Email'})
mysql 解法, 执行用时: 418 ms, 内存消耗: N/A, 提交时间: 2018-08-22 11:44:25
# Write your MySQL query statement below select Email from Person group by Email having(count(Email))>1;