删除一张表中重复的值以及查找出表中重复两条以上的数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/WKissa/article/details/79076548
-- SELECT MIN(id) FROM ctydetail GROUP BY originalcode HAVING COUNT(originalcode) > 1
-- SELECT originalcode FROM ctydetail GROUP BY originalcode HAVING COUNT(originalcode) > 1
-- SELECT id FROM ctydetail WHERE originalcode IN ( SELECT originalcode FROM ctydetail GROUP BY originalcode HAVING COUNT(originalcode) > 1 ) AND id NOT IN ( SELECT MIN(id) FROM ctydetail GROUP BY originalcode HAVING COUNT(originalcode) > 1 )
-- SELECT id FROM ctydetail WHERE originalcode IN ( SELECT originalcode FROM ctydetail GROUP BY originalcode HAVING COUNT(originalcode) > 1 )
-- DELETE FROM  ctydetail WHERE originalcode IN ( select originalcode from (SELECT originalcode FROM ctydetail GROUP BY originalcode HAVING COUNT(originalcode) > 1 ) as temp1) AND id NOT IN (select * from ( SELECT MIN(id) FROM ctydetail GROUP BY originalcode HAVING COUNT(originalcode) > 1 ) a)
-- SELECT COUNT(*) AS a FROM ctydetail GROUP BY originalcode ORDER BY a DESC
展开阅读全文

没有更多推荐了,返回首页