You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
delete person from person, person p2
whereperson.email=p2.emailandperson.id>p2.id;
解析
和方法一一样。
SQL:方法三
delete person from person,
(
selectmin(id) as id, email from person group by email havingcount(email) >1) as p2
whereperson.email=p2.emailandperson.id!=p2.id;
解析
将 person 安装 email 进行分组,并用 having 筛选出重复的最小 id
将这个临时表在和 person 进行一起联查,条件是 person.email = p2.email 并且不能和临时表的 id 相同,结果就是要删除的数据。
The text was updated successfully, but these errors were encountered:
题目
删除
person
表中所有重复的电子邮箱,重复的邮箱只保留id
最小的那个。SQL:方法一
解析
自连接,连接条件是
person.email = p2.email
筛选出person.id > p2.id
,这个是要删除的。SQL:方法二
解析
和方法一一样。
SQL:方法三
解析
person
安装email
进行分组,并用having
筛选出重复的最小id
person
进行一起联查,条件是person.email = p2.email
并且不能和临时表的id
相同,结果就是要删除的数据。The text was updated successfully, but these errors were encountered: