Chinaunix首页 | 论坛 | 博客
  • 博客访问: 530221
  • 博文数量: 88
  • 博客积分: 2256
  • 博客等级: 大尉
  • 技术积分: 921
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-08 23:20
个人简介

积硅步,行千里

文章分类

全部博文(88)

文章存档

2019年(5)

2018年(1)

2016年(15)

2015年(23)

2013年(3)

2012年(6)

2011年(3)

2010年(22)

2009年(10)

我的朋友

分类: SQLServer

2016-03-10 17:00:51


  1. 用SQL语句,删除掉重复项只保留一条
  2. 在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢
  3. 1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
  4. select * from people
  5. where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)

  6. 2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
  7. delete from people
  8. where peopleName in (select peopleName from people group by peopleName having count(peopleName) > 1)
  9. and peopleId not in (select min(peopleId) from people group by peopleName having count(peopleName)>1)

  10. 3、查找表中多余的重复记录(多个字段)
  11. select * from vitae a
  12. where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

  13. 4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
  14. delete from vitae a
  15. where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
  16. and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)

  17. 5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
  18. select * from vitae a
  19. where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
  20. and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)

  21. 6.消除一个字段的左边的第一位:

  22. update tableName set [Title]=Right([Title],(len([Title])-1)) where Title like '村%'

  23. 7.消除一个字段的右边的第一位:

  24. update tableName set [Title]=left([Title],(len([Title])-1)) where Title like '%村'

  25. 8.假删除表中多余的重复记录(多个字段),不包含rowid最小的记录
  26. update vitae set ispass=-1
  27. where peopleId in (select peopleId from vitae group by peopleId

阅读(1274) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~