相同元组删除的问题??

RogerWT 2005-03-22 05:04:26
一表中员组有如下相同数值:
字段
a
a
b
b
c
c
d
d
现想删除重复元组,只留下一个数值,怎么做?
我有如下两种方法:
1、用游标一个个的取出来在与下一行值比较应该可以,
2、新建个表,然后查处distinct值,然后插入其中应该可以,还有什么方法呢?
请指教,谢过了!
...全文
70 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wyb0026 2005-03-22
  • 打赏
  • 举报
回复
create table test (a char(10),b char(10))
insert test select 'a','1'
insert test select 'b','1'
insert test select 'b','1'
insert test select 'b','1'
insert test select 'a','1'
insert test select 'a','1'
insert test select 'c','1'
insert test select 'c','1'

select * into #t from test
group by a,b

truncate table test

insert into test select * from #t

select * from test

drop table #t
drop table test
jinjazz 2005-03-22
  • 打赏
  • 举报
回复
distinct是最好的
jackeychen0920 2005-03-22
  • 打赏
  • 举报
回复
delete from tablename where id in(select id from tablename a where
(select count(id) as Ts from tablename b where a.id=b.id)>1 )
删除表tablename里的字段ID重读记录
xluzhong 2005-03-22
  • 打赏
  • 举报
回复
alter table tablename add id int identity(1,1)
go
select *
from tablename a
where exists(select 1 from tablename where col=a.col and id<a.id)
---
select *
from tablename
where id not in(select min(id) from tablename group by col)
go
alter tablename drop column id

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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