delete from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) >1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)法一: 用Group by
语句 此查找很快的select count(num), max(name) from student –查找表中num列重复的,列出重复的记录数,并列出
他的name属性group by numhaving count(num) >1 –按num分组后找出表中num列重复,即出现次数大于一次delete from student(上面Select的)这样的话就把所有重复的都删除了。—–慎重法二:当表比较大(例如10万条以上)时,这个方法的效率之差令人无法忍受,需要另想办法:—- 执行下面SQL语句后
就可以显示所有DRAWING和DSNO相同且重复的记录SELECT * FROM EM5_PIPE_PREFABWHERE ROWID!=(SELECT MAX(ROWID) FROM EM5_PIPE_PREFAB D –D相当于First,SecondWHERE EM5_PIPE_PREFAB.DRAWING=D.DRAWING ANDEM5_PIPE_PREFAB.DSNO=D.DSNO)—- 执行下面SQL语句后就可以删除所有DRAWING和DSNO相同且重复的记录DELETE FROM EM5_PIPE_PREFABWHERE ROWID!=(SELECT MAX(ROWID) FROM EM5_PIPE_PREFAB DWHERE EM5_PIPE_PREFAB.DRAWING=D.DRAWING ANDEM5_PIPE_PREFAB.DSNO=D.DSNO)法一: 用Group by语句 此查找很快的select count(num), max(name) from student –查找表中num列重复的,列出重复的记录数,并列出他的name属性group by numhaving count(num) >1 –按num分组后找出表中num列重复,即出现次数大于一次delete from student(上面Select的)这样的话就把所有重复的都删除了。—–慎重法二:当表比较大(例如10万条以上)时,这个方法的效率之差令人无法忍受,需要另想办法:—- 执行下面SQL语句后就可以显示所有DRAWING和DSNO相同且重复的记录SELECT * FROM EM5_PIPE_PREFABWHERE ROWID!=(SELECT MAX(ROWID) FROM EM5_PIPE_PREFAB D –D相当于First,SecondWHERE EM5_PIPE_PREFAB.DRAWING=D.DRAWING ANDEM5_PIPE_PREFAB.DSNO=D.DSNO)—- 执行下面SQL语句后就可以删除所有DRAWING和DSNO相同且重复的记录DELETE FROM EM5_PIPE_PREFABWHERE ROWID!=(SELECT MAX(ROWID) FROM EM5_PIPE_PREFAB DWHERE EM5_PIPE_PREFAB.DRAWING=D.DRAWING ANDEM5_PIPE_PREFAB.DSNO=D.DSNO)只需要改下sql语句就可以了, 把select pxnr,xxsc from T_XYPXJLCB where XYXXFID= '441900012201410287'" 改为如下语句。
select pxnr,MAX(xxsc) from T_XYPXJLCB where XYXXFID= '441900012201410287'"
评论列表(0条)