LeetCode Database: Delete Duplicate Emails
2015-10-21 23:10
429 查看
Write a SQL query to delete all duplicate email entries in a table named
For example, after running your query, the above
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
Persontable 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 )
相关文章推荐
- 【人工智能】传教士和野人问题(M-C问题)
- 十八.利用QPainter作图
- AI CDR文字路径
- @property中的 strong retain copy weak 和assign
- 第 三 十 七 天:RAID 简 介 与 查 看
- 【二维线段树】hdu 4819 Mosaic
- Contains Duplicate && Contains Duplicate II
- 杭电2473-Junk-Mail Filter
- 【PAT】1079. Total Sales of Supply Chain (25)
- Foxmail 7.2 导入CSV文件的格式问题
- AVAIO流学习总结
- [Leetcode] Climbing Stairs
- saiku-添加数据源以及保证数据源的一致性
- NSSearchPathDirectoriesDomains的理解
- RabbitMQ消息队列(一): Detailed Introduction 详细介绍
- saiku - olap数据源管理
- Jenkins邮件插件的配置(Email Extension Plugin)
- Baidu WIFI Music Box
- vm manager failed to contact configuration server
- 26-main方法不能执行