sql2000数据库清除重复数据的二种方法
程序员文章站
2023-10-20 11:18:13
使用游标实现复制代码 代码如下:declare @id1 int,@oldid int,@e_recordid int ,@olde_recordid intdeclare...
使用游标实现
复制代码 代码如下:
declare @id1 int,@oldid int,@e_recordid int ,@olde_recordid int
declare price cursor
for select id ,e_recordid from evaeve order by e_recordid desc
open price
fetch next from price into @oldid,@olde_recordid
while @@fetch_status = 0
begin
fetch next from price
into @id1,@e_recordid
if @olde_recordid=@e_recordid
begin
delete from evaeve where id=@id1
end
set @oldid=@id1
set @olde_recordid=@e_recordid
end
close price
deallocate price
使用sql语句实现
复制代码 代码如下:
delete from evaeve where id not in( select max(id) from evaeve group by e_recordid)
推荐阅读