MySQL查找出重复数据,然后把删除重复的数据,只保留一条。
其中,id是唯一的字段;而coupons_number是要发送的优惠券,即存在重复的字段。下面是一整条的SQL语句。
DELETE FROM sdb_b2c_new_coupons_number WHERE id in ( SELECT id FROM ( SELECT MAX(id) AS id, COUNT(coupons_number) AS count FROM sdb_b2c_new_coupons_number GROUP BY coupons_number HAVING count > 1 ORDER BY count DESC ) AS temp );
MySQL删除重复的数据,就是执行类似以上的SQL语句。有需要的朋友可以参考一下!