用java文件如何去掉excel中的重复数据(如有三列完全相同的数据视为重复输入,重复的数据只保留第一条)

用java文件如何去掉excel中的重复数据(如有三列完全相同的数据视为重复输入,重复的数据只保留第一条),第1张

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'"


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9995076.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存