码迷,mamicode.com
首页 > 数据库 > 详细

处理数据库重复数据问题

时间:2019-03-08 16:44:11      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:res   bsp   oct   tor   完全   custom   cto   查找   code   

1.删除数据库重复数据,保留id最小的数据
 
DELETE FROM c_customer_product
WHERE fid IN
(
SELECT fid FROM
(
SELECT fid FROM c_customer_product
WHERE (fcustomer_id,fproduct_id,fis_delete) IN
(SELECT fcustomer_id,fproduct_id,fis_delete
FROM c_customer_product GROUP BY fcustomer_id,fproduct_id,fis_delete HAVING COUNT(*)>1)
AND fid NOT IN
(SELECT MIN(fid) FROM c_customer_product GROUP BY fcustomer_id,fproduct_id,fis_delete HAVING COUNT(*)>1)
) fidresult
)
 
2.查找某个表中某几条记录完全相同的数据
 
如 :查询 c_customer表中fdoctor_id,fhospital_id,fis_delete数据一样的记录
SELECT fid FROM
(
SELECT fid FROM c_customer
WHERE (fdoctor_id,fhospital_id,fis_delete) IN
(SELECT fdoctor_id,fhospital_id,fis_delete
FROM c_customer GROUP BY fdoctor_id,fhospital_id,fis_delete HAVING COUNT(*)>1)
AND fid NOT IN
(SELECT MIN(fid) FROM c_customer GROUP BY fdoctor_id,fhospital_id,fis_delete HAVING COUNT(*)>1)
) fidresult

 

处理数据库重复数据问题

标签:res   bsp   oct   tor   完全   custom   cto   查找   code   

原文地址:https://www.cnblogs.com/liuchq/p/10496463.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!