处理数据库重复数据问题

Posted liuchq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了处理数据库重复数据问题相关的知识,希望对你有一定的参考价值。

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

 

以上是关于处理数据库重复数据问题的主要内容,如果未能解决你的问题,请参考以下文章

在Android中将数据从基本活动发送到片段[重复]

将数据从活动传递到片段[重复]

android片段-数据传递-最佳实践[重复]

发送从活动数据到片段:NPE [重复]

如何从片段获取数据到另一个活动? (不是容器活动)[重复]

如何使用列表视图在选项卡式活动的片段中呈现 SQLite 表数据 [重复]