LeetCode DB : 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 |
+----+------------------+
考察删除中运用where条件
# Write your MySQL query statement below
delete from Person where id in (select * from (select A.id from Person as A, Person as B where A.id>B.id and A.Email = B.Email) X);
另外一种方法,也是用了嵌套查询
delete from Person where Id not in
(select min_id from (select min(Id) as min_id from Person group by Email) as Cid) ;
LeetCode DB : Delete Duplicate Emails的更多相关文章
- LeetCode DB: Duplicate Emails
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
- LeetCode Database: 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【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 ...
随机推荐
- BZOJ 3357--[Usaco2004]等差数列(STL&DP)
3357: [Usaco2004]等差数列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 516 Solved: 241[Submit][Statu ...
- jQuery基础(2)
一.jQuery的属性操作 jQuery的属性操作分为四部分: html标签属性操作:是对html文档中的标签属性进行读取,设置和移除操作.比如attr().removeAttr(): DOM属性操作 ...
- 读取型CSRF-需要交互的内容劫持
本文作者:i春秋作家——jing0102 前言 最近在挖洞,"实践出真知"这句话说的很对,在实际挖掘过程中我会思考很多东西,跟朋友一起准备做一份手册,忽然的想到了一些漏洞的定义和规 ...
- 跟着刚哥学习Spring框架--JDBC(六)
Spring的JDBC框架 Spring JDBC提供了一套JDBC抽象框架,用于简化JDBC开发. Spring主要提供JDBC模板方式.关系数据库对象化方式.SimpleJdbc方式.事务管理来简 ...
- String s=“dd”和String s=new String("dd")区别
Java中String s="dd"的话会先检查常量池中是否有"dd"这个字符串,如果没有则创建一个,然后将s指向字符串的地址,而new String(&quo ...
- day 74 vue 2 axios数据请求 以及组件的学习
前情提要: vue 学习二: 一: 通过axios实现数据请求 1:json数据语法 json数据对象类似于JavaScript中的对象,但是它的键对应的值里面是没有函数方法的,值可以是普通变量, ...
- [Leetcode]120.三角形路径最小和
---恢复内容开始--- 题目的链接 简单的动态规划题,使用了二维dp数组就能很好的表示. 由于有边界的问题,所以这个dp数组为 dp[n+1][n+1]. dp[i][j]意思是终点为(i-1,j- ...
- 【sping揭秘】5、IOC容器(一)
OC容器实现过程 1. 容器启动阶段,读取配置文件,解析文件BeanDefinitionReader 2. Bean 实例化阶段 关于BeanFactoryPostProcessor 插手spring ...
- 11-01 Java 开发工具 eclipse从下载、安装到实际使用的详细教程
Eclipse和MyEclipse简介 Eclipse是一种可扩展的开放源代码的IDE.起始于1999年4月,由OTI和IBM两家公司的IDE产品开发组组建. 2001年11月,IBM公司捐出价值4 ...
- java中result和resultSet
ResultSet: 1,定义 public interface ResultSet 表示数据库结果集的数据表,通常通过执行查询数据库的语句生成. 2,获得 State ...