当前位置:网站首页>Leetcode Day5 delete duplicate email
Leetcode Day5 delete duplicate email
2022-07-28 19:44:00 【wyqgg123】
196. Delete duplicate email
The difficulty is simple
Write a SQL Inquire about , To delete Person All duplicate email addresses in the table , The duplicate mailbox only keeps Id Minimum the .
±—±-----------------+
| Id | Email |
±—±-----------------+
| 1 | [email protected] |
| 2 | [email protected] |
| 3 | [email protected] |
±—±-----------------+
Id It's the primary key of this table .
for example , After running your query , above Person The table should return the following lines :
±—±-----------------+
| Id | Email |
±—±-----------------+
| 1 | [email protected] |
| 2 | [email protected] |
±—±-----------------+
Tips :
perform SQL after , The output is the whole Person surface .
Use delete sentence .
Answer key :
It is not difficult for us to see from the meaning of the title , This question needs to use delete Statement to delete duplicate Email value , Here we can disassemble the subject , First, repeat Email Find out , Then find out Email Delete the result .
1、 Find duplicate Email result
The implementation here is to realize query repetition through self table connection Email, The connection condition is a.Email be equal to b.Email, After connection query , We need to judge ourselves in terms of conditions Email Equal rows are deleted , What you get in this way is repetition Email.
select a.*
from Person a
left join Person b
on a.Email = b.Email
where a.Id > b.Id
The operation results are shown in the following table :
| id | |
|---|---|
| 3 | [email protected] |
2、 Delete the queried data
All we need to do here is select Replace statement with delete Sentence can be used
sql Code
delete a.*
from Person a
left join Person b
on a.Email = b.Email
where a.Id > b.Id
Data in the table after deleting duplicate data :
| Id | |
|---|---|
| 1 | [email protected] |
| 2 | [email protected] |
边栏推荐
- Leetcode day2 连续出现的数字
- MySQL8 tmp_ table_ Size and Max_ heap_ table_ size
- Taking the opportunity of digital transformation, how can 3C enterprises achieve efficient collaboration through SRM supplier cloud collaboration platform?
- redis 主从架构(sizeof函数怎么计算)
- Rust Getting Started Guide (crite Management)
- 中国首枚芯片邮票面世:内置120um超薄NFC芯片
- MySQL8 tmp_table_size和max_heap_table_size
- Question bank and answers of the latest national fire-fighting facility operators (intermediate fire-fighting facility operators) in 2022
- VAE: understanding and implementation of variational self encoder
- npm安装和卸载全局包
猜你喜欢

认识中小型局域网WLAN

Sword finger offer II 109. unlock the password lock

云计算笔记part.2——应用管理

shared_ptr 和 make_shared 的使用

Rust 入门指南(rustup, cargo)

How openocd directly downloads programs to STM32 board through stlink (solved)

Convertible bond concept table x notation gives you a convenient and fast experience!

在矩池云快速安装torch-sparse、torch-geometric等包

idea properties文件显示\u不显示中文的解决

MATLAB实现的图像分割之边缘检测和连接
随机推荐
【微信小程序开发】页面导航与传参
BeanFactory not initialized or already closed - call ‘refresh‘ before accessing beans via the Applic
MySQL performance testing tool sysbench learning
Investment of 3.545 billion yuan! Gree Group participates in Xiaomi industry fund
leetcode day3 查找重复的电子邮箱
Salt SSH of saltstack
测试开发备忘
Taking the opportunity of digital transformation, how can 3C enterprises achieve efficient collaboration through SRM supplier cloud collaboration platform?
npm安装和卸载全局包
VAE: understanding and implementation of variational self encoder
Germany and Portugal have announced that they will not disable Huawei 5g equipment, but Germany will set strict restrictions!
China's first chip stamp released: built-in 120um ultra-thin NFC chip
Failed to install app-debug.apk: Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]
Design of library management database system
[notes] Networking: Internet product managers change the world
助力面板行业创新,FPGA将成屏厂TCON最佳选择?
基于MATLAB的函数拟合
Business visualization - let your flowchart "run" (4. Actual business scenario test)
Rust Getting Started Guide (rustup, cargo)
C language cycle sentence strengthening exercises