编写一个 SQL 查询,来删除 Person 表中所有重复的电子邮箱,重复的邮箱里只保留 Id 最小 的那个。

+----+------------------+
| Id | Email |
+----+------------------+
| 1 | john@example.com |
| 2 | bob@example.com |
| 3 | john@example.com |
+----+------------------+
Id 是这个表的主键。

例如,在运行你的查询语句之后,上面的 Person 表应返回以下几行:

+----+------------------+

| Id | Email |

+----+------------------+

| 1 | john@example.com |

| 2 | bob@example.com |

+----+------------------+

题解:

技巧:将同一个表select两次,分别为表a,表b

DELETE p1.* FROM
Person p1,Person p2
WHERE
p1.Email = p2.Email AND p1.Id > p2.Id;

摘自:

https://leetcode-cn.com/problems/delete-duplicate-emails/solution/shan-chu-zhong-fu-de-dian-zi-you-xiang-by-leetcode/

[LeetCode] 196.删除重复的电子邮箱的更多相关文章

  1. [LeetCode]196. 删除重复的电子邮箱(delete)

    题目 编写一个 SQL 查询,来删除 Person 表中所有重复的电子邮箱,重复的邮箱里只保留 Id 最小 的那个. +----+------------------+ | Id | Email | ...

  2. LeetCode:196.删除重复的电子邮箱

    题目链接:https://leetcode-cn.com/problems/delete-duplicate-emails/ 题目 编写一个 SQL 查询,来删除 Person 表中所有重复的电子邮箱 ...

  3. 【leetcode 简单】 第五十三题 删除重复的电子邮箱

    编写一个 SQL 查询,来删除 Person 表中所有重复的电子邮箱,重复的邮箱里只保留 Id 最小 的那个. +----+------------------+ | Id | Email | +-- ...

  4. [SQL]LeetCode196. 删除重复的电子邮箱 | Delete Duplicate Emails

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  5. mysql查询之 连续出现的数字,重复出现的邮箱,删除重复的电子邮箱

    1.编写一个 SQL 查询,查找所有至少连续出现三次的数字. +----+-----+ | Id | Num | +----+-----+ | 1 | 1 | | 2 | 1 | | 3 | 1 | ...

  6. [LeetCode] 182.查找重复的电子邮箱

    编写一个 SQL 查询,查找 Person 表中所有重复的电子邮箱. 示例: +----+---------+ | Id | Email | +----+---------+ | 1 | a@b.co ...

  7. LeetCode 196. Delete Duplicate Emails (删除重复的电子邮箱)

    题目标签: 题目给了我们一个 email 的表格,让我们删除重复的. 建立Person p1,Person p2,当email 相同时,而且 p1 id 要大于 p2 id 时候,删除这一行. Jav ...

  8. LeetCode:182.查找重复的电子邮箱

    题目链接:https://leetcode-cn.com/problems/duplicate-emails/ 题目 编写一个 SQL 查询,查找 Person 表中所有重复的电子邮箱. 示例: +- ...

  9. [SQL]LeetCode182. 查找重复的电子邮箱 | Duplicate Emails

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

随机推荐

  1. 72.Minimum Window Substring(最小子串窗口)

    Level:   Hard 题目描述: Given a string S and a string T, find the minimum window in S which will contain ...

  2. Fiddler查看IP和响应时间

    原文:Fiddler查看IP和响应时间 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/si ...

  3. C#设计模式:工厂模式

    一,工厂模式 using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...

  4. 常见前端面试题JS部分

    1.闭包 2.JS操作和获取cookie //创建cookie function setCookie(name, value, expires, path, domain, secure) { var ...

  5. Python-编码这趟浑水

    最近听Alex讲到python编码,还特意用博客讲解,觉得问题严重了,于是翻看各种博客,先简单的对编码错误做一个总结,其他的后续慢慢补上,还得上班.还得学习.还得写博客?感觉有点吃不消了.各位大神不喜 ...

  6. What are draw calls(绘制命令) and what are batches(批)

    Resolution It is important to know what are draw calls and what are batches. A draw call is a call t ...

  7. shell命令结果重定向

  8. rpm - RPM 软件包管理器

    SYNOPSIS 查询和校验软件包: rpm {-q|--query} [select-options] [query-options] rpm {-V|--verify} [select-optio ...

  9. BZOJ4386 [POI2015]Wycieczki 矩阵+倍增

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4386 题解 一眼就可以看出来是邻接矩阵快速幂. 可是这里的边权不为 \(1\).不过可以发现, ...

  10. pycharm远程连接的步骤(有一项需特别注意)

    1.设置远程服务器,在这里配置服务器地址等: 要注意下边的这个mappings设置好,跟编译器的path mapping设置为同一个,这里我没设置为同一个,后边就出现了点问题. 2.配置远程的编译器 ...