oracle根据字段去查询表重复数据

文章介绍了在数据库中使用SQL语句进行数据清洗,包括通过`fid`和`fpro_code`字段的分组计数来找出重复项,并使用条件删除非唯一行的操作。展示了针对不同表结构(如`t_ams_product`和`t_rp_org`)的示例。
摘要由CSDN通过智能技术生成

单字段
1、查询
select * from t_ams_product where fid in (select fid from t_ams_product group by fid having count(fid) > 1)

2、删除
根据id
delete from t_ams_product where (fid) in ( select fid from t_ams_product group by fid having count(fid) > 1) and rowid not in (select min(rowid) from t_ams_product group by fid having count(*) > 1);

根据其他字段
delete from t_ams_product where fpro_code in (select fpro_code from t_ams_product group by fpro_code having count (fpro_code) > 1 ) and fid not in (select min(fid) from t_ams_product group by fpro_code having count(fpro_code) > 1 )

多字段
删除
delete from t_rp_org a where (a.forg_type ,a.forg_name) in (select forg_type ,forg_name from t_rp_org group by forg_type ,forg_name having count() > 1) and rowid not in (select min(rowid) from t_rp_org group by forg_type ,forg_name having count()>1)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值