首页  »   MySQL

剔除mysql重复记录(多字段判断)

网友分享于:2018-04-03  浏览:3次
删除mysql重复记录(多字段判断)

/**************查找****************/

 SELECT * from (SELECT *, CONCAT(pro_name,send_approve_money,final_money,rate,final_time,pro_code) as MUITI from bus_pro_closeapprove) c1 WHERE c1.MUITI in 

(

    SELECT MUITI from (SELECT CONCAT(pro_name,send_approve_money,final_money,rate,final_time,pro_code) as MUITI from bus_pro_closeapprove) c2 GROUP BY MUITI HAVING count(MUITI) > 1

) ORDER BY pro_name;

 

/**************删除****************/

DELETE from bus_pro_closeapprove WHERE id not in 

(

    SELECT id from (SELECT *, MAX(create_date) as maxCreateDate, CONCAT(pro_name,send_approve_money,final_money,rate,final_time,pro_code) as MUITI from bus_pro_closeapprove GROUP BY MUITI) t

)

相关解决方案

最新解决方案