7个字段 联合主键 10W记录删除重复记录
求高效率的方法?
苯方法如下:
delete from PO_QMPLAN where rowid not in (
select max(t1.rowid) from PO_QMPLAN t1 group by
t1.MATNR,t1.plnty,t1.plnnr,t1.VERWE,t1.MERKNR,t1.VORNR,t1.WERKS,t1.VERWMERKM)
望大家给出的高效率的方法了!
联合, 记录, 重复, delete, from
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Enable Novalidate
如果重复很多
create table PO_QMPLAN_BAK as select t1.* from PO_QMPLAN t1
where t1.rowed = (select max(rowid) from PO_QMPLAN t2
where t1.MATNR=t2.MATNR and
t1.plnty=t2.plnty and
t1.plnnr=t2.plnnr and
t1.VERWE=t2.VERWE and
t1.MERKNR=t2.MERKNR and
t1.VORNR=t2.VORNR and
t1.WERKS=t2.WERKS and
t1.VERWMERKM=t2.VERWMERKM
);
truncate table PO_QMPLAN;
如果是9.2或以后
drop table PO_QMPLAN;
alter table PO_QMPLAN_BAK rename to PO_QMPLAN;
alter table PO_QMPLAN add primary key (,,,,);
如果是9.2以前
alter table PO_QMPLAN drop primary key;
insert into PO_QMPLAN select * from PO_QMPLAN_BAK ;
truncate table PO_QMPLAN_BAK;
drop table PO_QMPLAN_BAK;
alter table PO_QMPLAN add primary key (,,,,);
但是我很奇怪,既然有主键,重复记录怎么可能有呢,是4.1的玩笑?
以下语句把相同的记录全部找出来了
select count(rowid), MATNR ,plnal, VERWE,
MERKNR, plnnr, VORNR, WERKS, VERWMERKM from po_qmplan group by MATNR ,plnal, VERWE,
MERKNR, plnnr, VORNR, WERKS, VERWMERKM having count(rowid) >1
机器慢,没办法啊
我执行了那个SQL 还是等了很常时间 现在正在执行ING
是8个字段的联合主键吧?
delete from table PO_QMPLAN t1
where t1.rowed != (select max(rowed) from PO_QMPLAN t2
where t1.MATNR=t2.MATNR and
t1.plnty=t2.plnty and
t1.plnnr=t2.plnnr and
t1.VERWE=t2.VERWE and
t1.MERKNR=t2.MERKNR and
t1.VORNR=t2.VORNR and
t1.WERKS=t2.WERKS and
t1.VERWMERKM=t2.VERWMERKM
)