题解 | #删除emp_no重复的记录,只保留最小的id对应的记录。#
删除emp_no重复的记录,只保留最小的id对应的记录。
http://www.nowcoder.com/practice/3d92551a6f6d4f1ebde272d20872cf05
emp_no重复的记录
select emp_no
from titles_test
group by emp_no
having count(emp_no)>1
最小的id对应的记录
select min(id)
from titles_test
group by emp_no
having count(emp_no)>1
删除emp_no重复的记录,只保留最小的id对应的记录。
delete from titles_test
where emp_no in(
select emp_no
from titles_test
group by emp_no
having count(emp_no)>1)
and id not in (
select min(id)
from titles_test
group by emp_no
having count(emp_no)>1)