方式一
-- 810
-- SELECT count(DISTINCT model) FROM phone_price
-- 965
-- SELECT count(1) FROM phone_price
为了保险起见,建议操作时,复制表测试一下
-- delete from phone_price_copy1
-- where model in (select pname from (select model as pname from phone_price_copy1 group by model having count(model) > 1) a)
-- and id not in (select pid from (select min(id) as pid from phone_price_copy1 group by model having count(model) > 1 ) b)
--
-- 最后查询数据为810
-- SELECT count(1) FROM phone_price_copy1
方式二,下面这种方式适合多字段组合去重的
直接利用分组去重,取最小的c_id,获得最小的id就是不需要删除的
select MIN(c_id) as c_id,COUNT(1) as count2 from test group by
c_product_id,c_channel_trader_id,c_platform_id,c_check_type
having count2 > 1
delete from test where c_id not in(....)