首页 > 其他 > 详细

输出重复数据

时间:2016-10-19 13:50:32      阅读:239      评论:0      收藏:0      [点我收藏+]

 sql:

       select distinct * into #tmp from tablename

       drop table tablename

       select * into tablename from #tmp

       drop table #tmp

2.用游标进行删除

declare @max integer,@id integer 
declare cur_rows cursor local for select 主字段,count(*) from tablename group by 主字段 having count(*) > 1 
open cur_rows 
fetch cur_rows into @id,@max 
while @@fetch_status=0 
begin 
select @max = @max -1 
set rowcount @max 
delete from tablename where 主字段= @id 
fetch cur_rows into @id,@max 
end 
close cur_rows 
set rowcount 0

输出重复数据

原文:http://www.cnblogs.com/watchfluture/p/5976787.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!