# Write your MySQL query statement below
196. 删除重复的电子邮箱
表: Person
+-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | email | varchar | +-------------+---------+ id是该表的主键列。 该表的每一行包含一封电子邮件。电子邮件将不包含大写字母。
编写一个 SQL 删除语句来 删除 所有重复的电子邮件,只保留一个id最小的唯一电子邮件。
以 任意顺序 返回结果表。 (注意: 仅需要写删除语句,将自动对剩余结果进行查询)
查询结果格式如下所示。
示例 1:
输入: Person 表: +----+------------------+ | id | email | +----+------------------+ | 1 | john@example.com | | 2 | bob@example.com | | 3 | john@example.com | +----+------------------+ 输出: +----+------------------+ | id | email | +----+------------------+ | 1 | john@example.com | | 2 | bob@example.com | +----+------------------+ 解释: john@example.com重复两次。我们保留最小的Id = 1。
原站题解
pythondata 解法, 执行用时: 312 ms, 内存消耗: 60.2 MB, 提交时间: 2023-08-09 17:16:49
import pandas as pd # Modify Person in place def delete_duplicate_emails(person: pd.DataFrame) -> None: person.sort_values(by='id', inplace=True) person.drop_duplicates(subset='email', keep='first', inplace=True)
mysql 解法, 执行用时: 1728 ms, 内存消耗: 0 B, 提交时间: 2022-05-30 10:20:52
# Please write a DELETE statement and DO NOT write a SELECT statement. # Write your MySQL query statement below # Write your MySQL query statement below delete p1 from Person p1, Person p2 where p1.Email=p2.Email and p1.Id > p2.Id;
mysql 解法, 执行用时: 1350 ms, 内存消耗: N/A, 提交时间: 2018-08-22 15:24:25
# Write your MySQL query statement below delete p1 from Person p1, Person p2 where p1.Email=p2.Email and p1.Id > p2.Id;