查找重复数据sql(思路就是根据需要判断重复数据的字段分组,根据having大于2的就是重复的)
--查找某表重复数据
select BUSS_TYPE_ID,
BUSS_TYPE,
TRADE_VARIETY_ID,
TRADE_VARIETY,
TRADE_SUBVARIETY_ID,
TRADE_SUBVARIETY,
TRADE_CODE,
TRADE_OBJECT,
count(id)
from T_RPT_BUSINESS_STRUCTURE
where jys_id=6
group by BUSS_TYPE_ID,
BUSS_TYPE,
TRADE_VARIETY_ID,
TRADE_VARIETY,
TRADE_SUBVARIETY_ID,
TRADE_SUBVARIETY,
TRADE_CODE,
TRADE_OBJECT
having count(id) >= 2;
删除重复数据的sql
delete from T_RPT_BUSINESS_STRUCTURE where
(BUSS_TYPE_ID,
BUSS_TYPE,
TRADE_VARIETY_ID,
TRADE_VARIETY,
TRADE_SUBVARIETY_ID,
TRADE_SUBVARIETY,
TRADE_CODE,
TRADE_OBJECT)
in(
select BUSS_TYPE_ID,
BUSS_TYPE,
TRADE_VARIETY_ID,
TRADE_VARIETY,
TRADE_SUBVARIETY_ID,
TRADE_SUBVARIETY,
TRADE_CODE,
TRADE_OBJECT
from T_RPT_BUSINESS_STRUCTURE
group by BUSS_TYPE_ID,
BUSS_TYPE,
TRADE_VARIETY_ID,
TRADE_VARIETY,
TRADE_SUBVARIETY_ID,
TRADE_SUBVARIETY,
TRADE_CODE,
TRADE_OBJECT
having count(id) >= 2
) and
id not in (
select min(id)
from T_RPT_BUSINESS_STRUCTURE
group by BUSS_TYPE_ID,
BUSS_TYPE,
TRADE_VARIETY_ID,
TRADE_VARIETY,
TRADE_SUBVARIETY_ID,
TRADE_SUBVARIETY,
TRADE_CODE,
TRADE_OBJECT
having count(id) >= 2
)
标签:VARIETY,重复,BUSS,TRADE,SUBVARIETY,sql,oracle,TYPE,ID From: https://blog.51cto.com/u_16071779/6190733