资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

oacle删除重复数据

--测试数据

成都创新互联专注于青山企业网站建设,响应式网站,商城建设。青山网站建设公司,为青山等地区提供建站服务。全流程按需定制,专业设计,全程项目跟踪,成都创新互联专业和态度为您提供的服务

create table test as select * from dba_objects;

insert into test select * from test;

--查看是否有重复数据

select * from test order by object_id;

--用rowid删除

select rowid,a.* from test a order by object_id;

--根据rowid分组

--办法(1)not in

DELETE FROM test WHERE ROWID NOT IN (SELECT MAX(ROWID) FROM test GROUP BY object_id)

--办法(2) in

DELETE FROM test a

 WHERE ROWID IN (SELECT ROWID

                   FROM (SELECT row_number() over(PARTITION BY object_id ORDER BY ROWID) rn,

                                a.*

                           FROM test a)

                  WHERE rn > 1)

--办法3 exists

DELETE FROM test a

 WHERE EXISTS (SELECT NULL

          FROM test b

         WHERE a.object_id = b.object_id

           AND a.rowid < b.rowid)

--in的等价写法

DELETE FROM test a

 WHERE object_id IN (SELECT object_id

                       FROM test b

                      WHERE a.object_id = b.object_id

                        AND a.rowid < b.rowid)

--如果要保留3条重复数据

DELETE FROM test a

 WHERE ROWID IN (SELECT ROWID

                   FROM (SELECT row_number() over(PARTITION BY object_id ORDER BY ROWID) rn,

                                a.*

                           FROM test a)

                  WHERE rn > 3)

                  


分享名称:oacle删除重复数据
本文URL:http://cdkjz.cn/article/ppjicc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220