通过单个字段(name)删除:delete from user where id not in
(
select id from
(
select max(id) id from user group by name
) a
);
通过多个字段(name,age)删除:delete from user where id not in
(
select id from
(
select max(id) id from user group by name,age
) a
);
其实差不多啦,不过这么写sql效率很低,欢迎大家有什么高效的写法教给我,谢谢啦!