知识点
- 首先将表按照emp_no进行分组,找出最小的id
- 筛选条件为不是这些id使用not in
- 删除记录delete from表名
代码
delete from titles_test
where id not in(
select min_id
from
(select min(id) as min_id
from titles_test
group by emp_no) as t1)
补充
delete from titles_test
where id not in
(select min(id)
from titles_test
group by emp_no)
这样写会报错,不能先select出同一表中的某些值,然后在同一语句中更改这个表,因此需要一个中间表。