这时候如果临时表中有重复数据,无论是主键字段businessid有重复,还是一整行有重复都会报出违反唯一主键约束错误。
方法:group by XX having count(*)>1,rowid,distinct,temporary table,procedure
1、查询表中的重复数据a.重复一个字段
b.重复多个字段
c.重复一整行
创建测试表:
代码如下:create table cfa (businessid number,customer varchar2(50),branc
刚开始,根据我的想法,这个很简单嘛,上sql语句
delete from zqzrdp where tel in (select min(dpxx_id) from zqzrdp group by tel having count(tel)>1);
执行,报错!!~!~
异常意为:你不能指定目标表的更新在FROM子句。傻了,MySQL 这样写,不行,让人郁闷。
难倒只能分步操作,蛋疼
以下是网友写的,同样是坑爹的代码,我机器上运行不了。
1. 查询需要删除的记录,会保留一条记录。
方法一 declare max integer,id integer declare cur_rows cursor local for select 主字段,count(*) from 表名 group by 主字段 having count(*) > 1 open cur_rows fetch cur_rows into id,max while fetch_status=0 begin select max = max -1 set rowcount max delete from