关于数据重复的问题··大虾近来帮忙?

新手学习着呢 2003-09-30 04:38:00
我的数据库中有近20000条记录,但是里面有1000条左右为重复数据,我现在想把里面的数据都修改为唯一值得,也就是说想把所有重复的数据删除掉,或者把所有单一的数据提取出来,不知如何操作?? 请大虾之点一二!!!!!!!!!!!!!!!!!
我的标里面重复的字段名为:username 是用户名 具体我该怎么做,,大虾快帮以下
···
...全文
36 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengdali 2003-09-30
  • 打赏
  • 举报
回复
如果你的表没有编号:

alter table 表 add 编号 int identity(1,1)

delete 你的表 where 编号 not in (select min(编号) from 你的表 group by username having sum(1)>1)

alter table 表 drop column 编
pengdali 2003-09-30
  • 打赏
  • 举报
回复
delete 你的表 where 编号 not in (select min(编号) from 你的表 group by username having sum(1)>1)
meteorlg 2003-09-30
  • 打赏
  • 举报
回复
delete from tablename where id in
(select max(id) from tablename group by username having count(*)>1)
antoversky 2003-09-30
  • 打赏
  • 举报
回复
如果是foxpro,select distinct *into table tablename
from source_tablename
若是sql server:select distinct *into tablename
from source_tablename
friendliu 2003-09-30
  • 打赏
  • 举报
回复
select distinct * into #tmp from tablename
go
delete from tablename
go
insert into tablename
select * from #tmp
go
txlicenhe 2003-09-30
  • 打赏
  • 举报
回复
delete 表 where username in
(select username from 表 group by username having sum(1) > 1)

34,874

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧