最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
DB2数据库重复记录删除sql语句
时间:2022-06-29 10:16:37 编辑:袖梨 来源:一聚教程网
--1.查询重复数据
| 代码如下 | 复制代码 |
|
select * from tableA where catentry_id in (select distinct catentry_id from tableA group by catentry_id,descitem_id having count(*)>1)@ |
|
--2.建立临时表,将所有重复数据存入该表
| 代码如下 | 复制代码 |
|
create table detailtemp1 like tableA@ insert into detailtemp1 |
|
--3。从原表中删除所有出现重复情况的记录
| 代码如下 | 复制代码 |
|
delete from tableA where catentry_id in (select distinct catentry_id from tableA group by catentry_id,descitem_id having count(*)>1)@ |
|
--4。用group by 分组,将临时表中的不重复记录插入原表中
| 代码如下 | 复制代码 |
|
insert into tableA
|
|
--5。删除临时表
| 代码如下 | 复制代码 |
|
drop table detailtemp1@ --end |
|
另外再分享几种办法
2、DB2删除重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
| 代码如下 | 复制代码 |
| delete from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1) | |
3、查找表中多余的重复记录(多个字段)
| 代码如下 | 复制代码 |
|
select * from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1) |
|
4、DB2删除重复记录(多个字段),只留有rowid最小的记录
| 代码如下 | 复制代码 |
|
delete from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1) and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1) |
|
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
| 代码如下 | 复制代码 |
|
select * from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1) and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1) |
|
6. 处理bas_information中去重,根据
| 代码如下 | 复制代码 |
| t.PISField001,t.PISField011,t.areaCode export to e:/bas_information.txt of del select s.HOUSEHOLDS, s.PISFIELD000, s.PISFIELD001, s.PISFIELD002, s.PISFIELD003, s.PISFIELD004, s.PISFIELD005, s.PISFIELD006, s.PISFIELD011, s.PISFIELD012, s.PISFIELD013, s.PISFIELD014, s.PISFIELD015, s.PISFIELD016, s.DEADDATE, s.QIANRUDATE, s.ZHIYE, s.JIATING, s.AREACODE, s.REG_DATE, s.ISLOGOUT from (select t.*,rownumber() over(partition by t.PISField001,t.PISField011,t.areaCode) as rn from bas_information t ) s where s.rn = 1; |
|
相关文章
- qq邮箱登录入口-QQ邮箱网页版登录入口 08-10
- AI写作助手小程序,能否颠覆我们的创作方式 08-10
- 如何利用AI助手提升公文写作效率 08-10
- 《我的世界手游》龙蛋怎么操作-龙蛋的操作技巧 08-10
- 如何高效整理营销策略?AI论文生成工具帮你高效完成企业年终总结及提示词解析 08-10
- 魔兽世界赞达拉战争使者在哪-赞达拉战争使者位置 08-10