LeetCode Database: Delete Duplicate Emails
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 |
+----+------------------+
# Write your MySQL query statement below delete from Person where Id not in
(
select Id from
(
select Id,
if(STRCMP(@prev, Email)=0, false, true) as Diff,
@prev := Email from
(select * from Person p2 order by Email, Id asc) x,
(select @prev := '') y
) t where t.Diff=true
)
LeetCode Database: Delete Duplicate Emails的更多相关文章
- LeetCode DB : Delete Duplicate Emails
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...
- leetcode 196. Delete Duplicate Emails 配合查询的delete
https://leetcode.com/problems/delete-duplicate-emails/description/ 题意要对原来的数据表进行删除,不删除不行,它每次只输出原来那个表. ...
- LeetCode 196. Delete Duplicate Emails (删除重复的电子邮箱)
题目标签: 题目给了我们一个 email 的表格,让我们删除重复的. 建立Person p1,Person p2,当email 相同时,而且 p1 id 要大于 p2 id 时候,删除这一行. Jav ...
- leetcode 196. Delete Duplicate Emails
# 慢,内连接delete p1 from Person p1, Person p2 where p1.Email=p2.Email and p1.Id>p2.Id delete from Pe ...
- [LeetCode] Delete Duplicate Emails 删除重复邮箱
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...
- LeetCode DB: Duplicate Emails
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
- leetcode【sql】 Delete Duplicate Emails
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...
- LeetCode - Delete Duplicate Emails
Discription:Write a SQL query to delete all duplicate email entries in a table named Person, keeping ...
- LeetCode——Delete Duplicate Emails(巧用mysql临时表)
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...
随机推荐
- 将web项目deploy到tomcat的方法
如果已经把整个项目发布到tomcat的webapps文件夹下,就不用再配置tomcat的server.xml了(也就是不用配置<Context>节点) 并且,你的项目的WEB-INF/li ...
- UX结合需求实例化进行设计开发
技 术 文 件 技术文件名称:实例化+UX需求分析实践:场景监控需求实例化 技术文件编号: 版 本:V1.0 共 32 页 (包括封面) 拟 制 廖开蒙.刀锋团队 审 核 ...
- apache-hadoop-1.2.1、hbase、hive、mahout、nutch、solr安装教程
1 软件环境: VMware8.0 Ubuntu-12.10-desktop-i386 jdk-7u40-linux-i586.tar.gz hadoop-1.2.1.tar.gz eclipse-d ...
- mysql命令分类(DML、DDL、DCL)
DML:数据操作语言(操作数据) SELECT - 从数据库表中获取数据 UPDATE - 更新数据库表中的数据 DELETE - 从数据库表中删除数据 INSERT INTO - 向数据库表中插入数 ...
- Linux内核等待队列
在Linux驱动程序设计中,可以使用等待队列来实现进程的阻塞,等待队列可看作保存进程的容器,在阻塞进程时,将进程放入等待队列,当唤醒进程时,从等待等列中取出进程. Linux 2.6内核提供了如下关于 ...
- poj -2229 Sumsets (dp)
http://poj.org/problem?id=2229 题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数.问你不同方案数之和是多少? n很大,所以输出后9位即可. dp[i] 表示组 ...
- DBContext
http://www.entityframeworktutorial.net/EntityFramework4.3/dbcontext-vs-objectcontext.aspx As you hav ...
- 编译Apache Hadoop2.2.0源代码
Hadoop2的学习资料很少,只有官网的少数文档.如果想更深入的研究hadoop2,除了仅看官网的文档外,还要学习如何看源码,通过不断的调试跟踪源码,学习hadoop的运行机制. 1.安装CentOS ...
- URAL1291. Gear-wheels
1291 不知道为嘛被分在DP里了 瞎写 注意没被别的轮带动的情况 初始为0 分母为1 #include <iostream> #include<cstdio> #includ ...
- C语言之移位操作
C语言很多操作都是以字节为单位进行的,但有时为了节约空间,很多系统程序中要求在比特位级别进行运算处理.C语言一同提供了六种位运算的运算符,分别为&(按位与),|(按位或),~(按位取反),^( ...