--查询哪些重复 select site_planning_id ,version from pl_macro_station_copy2 where site_planning_id in ( select site_planning_id from (select site_planning_id, count(*) as num from pl_macro_station_copy2 group by site_planning_id ) a where a.num >1 ) order by site_planning_id --删除site_planning_id,version完全重复的 delete from pl_macro_station_copy2 where detail_id not in ( SELECT MAX(detail_id) from pl_macro_station_copy2 GROUP BY site_planning_id,version ) --删除最小版本的 delete from pl_macro_station_copy2 where detail_id in( select detail_id from ( select c.detail_id,min(c.version) from ( select detail_id,site_planning_id ,version from pl_macro_station_copy2 where site_planning_id in ( select site_planning_id from pl_macro_station_copy2 where site_planning_id in ( select site_planning_id from (select site_planning_id, count(*) as num from pl_macro_station_copy2 group by site_planning_id ) a where a.num >1 ) order by site_planning_id ) group by detail_id,site_planning_id order by site_planning_id ) c group by c.detail_id ) d )