用SQL语句,熟练使用删除语句
在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
delete from people
where peopleName in (select peopleName from people group by peopleName having count(peopleName) > 1)
and peopleId not in (select min(peopleId) from people group by peopleName having count(peopleName)>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、删除表中多余的重复记录(多个字段),只留有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.消除一个字段的左边的第一位:
update tableName set [Title]=Right([Title],(len([Title])-1)) where Title like '村%'
7.消除一个字段的右边的第一位:
update tableName set [Title]=left([Title],(len([Title])-1)) where Title like '%村'
8.假删除表中多余的重复记录(多个字段),不包含rowid最小的记录
update vitae set ispass=-1
where peopleId in (select peopleId from vitae group by peopleId
- 1编程总结之关于编程的浅学习与深学习
- 2操作系统各大公司笔试题汇总
- 3如何重新安装IE浏览器
- 4双系统的安全卸载
- 5 WINXP优化精髓,如何加快开机与关机的速度
- 6Explorer.exe程序在系统中的作用
- 7操作系统进程描述
- 8内部网上的IP地址应该如何设置
- 9禁止光盘自动运行
- 10开始菜单响应速度过慢
- 11如何直接移动应用程序
- 12操作系统停止响应
- 13网卡没有安装成功该怎么解决
- 14命令设计模式
- 15巧妙安装各种Windows操作系统
- 16"文件保护"的解决方法,按以下步骤关闭文件保护
- 17WinXP瘦身办法
- 18常遇电脑故障应急处理方法
- 19销售库存管理软件 05.41.26
- 20Windows常用命令集
- 21入库出库管理软件架构之入库出库管理软件软件架构
- 22电脑显示器的相关设置与常见故障排除方法
- 23如何知道局域网中所有计算机的IP地址
- 24光驱读盘不正常
- 25无法升级更新
- 26禁止ipc$默认共享的方法
- 27什么是POP3
- 28应用程序不能启动
- 29打开硬盘分区出错
- 30群相册怎么看最近访客
成都公司:成都市成华区建设南路160号1层9号
重庆公司:重庆市江北区红旗河沟华创商务大厦18楼