leetcode原文引用:

Write a SQL query to delete all duplicate email entries in a table named Person,
keeping only unique emails based on its smallest Id.

+----+------------------+
| Id | Email |
+----+------------------+
| 1 | john@example.com |
| 2 | bob@example.com |
| 3 | john@example.com |
+----+------------------+
Id is the primary key column for this table.

For example, after running your query, the above Person table should
have the following rows:

+----+------------------+
| Id | Email |
+----+------------------+
| 1 | john@example.com |
| 2 | bob@example.com |
+----+------------------+

我的sql语句:

DELETE FROM Person
WHERE
id NOT IN (SELECT
id
FROM
(SELECT
MIN(id) AS id
FROM
Person
GROUP BY email) AS a);

leetcode数据库sql之Delete Duplicate Emails的更多相关文章

  1. leetcode【sql】 Delete Duplicate Emails

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

  2. [SQL]196. Delete Duplicate Emails

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

  3. [LeetCode] Delete Duplicate Emails 删除重复邮箱

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

  4. LeetCode——Delete Duplicate Emails(巧用mysql临时表)

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

  5. 【SQL】182. Duplicate Emails

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

  6. SQL Server Delete Duplicate Rows

    There can be two types of duplication of rows in a table 1. Entire row getting duplicated because th ...

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

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

  8. LeetCode Database: Delete Duplicate Emails

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

  9. LeetCode DB : Delete Duplicate Emails

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

  10. LeetCode - Delete Duplicate Emails

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

随机推荐

  1. PCIe诞生20年来最大变革!引入光学传输

    PCI-SIG组织官方宣布,已经成立新的光学工作组(Optical Workgroup),研究为PCIe规范引入光学传输接口的可能性. PCIe标准是Intel 2001年提出的,2003年发布1.0 ...

  2. 服了,一个ThreadLocal被问出了花

    分享是最有效的学习方式. 博客:https://blog.ktdaddy.com/ 故事 地铁上,小帅无力地倚靠着杆子,脑子里尽是刚才面试官的夺命连环问,"用过TheadLocal么?Thr ...

  3. 小知识:MySQL配置文件优先级

    今天在RHEL7上,严格按之前的安装规范文档,部署MySQL环境时,发现通过服务的方式启动MySQL失败: 关键错误是: log-error set to '/var/log/mariadb/mari ...

  4. Python_json类方法

    Python_json类方法 import requests import json headers = { "User-Agent": "Mozilla/5.0 (Li ...

  5. FUN GAME 一款普通的C++游戏

    凑合看吧,不是完整版. #include<bits/stdc++.h> #include<windows.h> #include<conio.h> using na ...

  6. NC26257 小雨坐地铁

    题目链接 题目 题目描述 小雨所在的城市一共有 \(m\) 条地铁线,分别标号为 1 号线,2 号线,--,m 号线.整个城市一共有 \(n\) 个车站,编号为 \(1 \sim n\) .其中坐 i ...

  7. sensitive-word v0.13 特性版本发布 支持英文单词全词匹配

    拓展阅读 sensitive-word-admin v1.3.0 发布 如何支持分布式部署? sensitive-word-admin 敏感词控台 v1.2.0 版本开源 sensitive-word ...

  8. 【Unity3D】缩放、平移、旋转场景

    1 前言 ​ 场景缩放.平移.旋转有两种实现方案,一种是对场景中所有物体进行同步变换,另一种方案是对相机的位置和姿态进行变换. ​ 对于方案一,如果所有物体都在同一个根对象下(其子对象或孙子对象),那 ...

  9. 【OpenGL ES】MVP矩阵变换

    1 前言 ​ 本文主要介绍 MVP 矩阵变换,其本质是线性变换,应用见→绘制立方体. Model:模型变换,施加在模型上的空间变换,包含平移变换(translateM).旋转变换(rotateM).对 ...

  10. Java设计模式-备忘录模式Memento

    介绍 备忘录模式(Memento Pattern)在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态.这样以后就可将该对象恢复到原先保存的状态. 可以这里理解备忘录模式:现实生 ...