消除sql2000里的重复数据
游标版 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
游标版
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)
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 delete from evaeve where id not in( select max(id) from evaeve group by E_RecordID)
上一篇: 理论+实操:搭建FTP服务,创建虚拟用户
推荐阅读
-
怎么把Sql2000数据库的备份文件恢复到Sql2005
-
2000条数据的数组,找出有重复值的索引
-
用户数据的重复,小弟我这个对于$result是不是理解错了
-
如何解决PHP里大量数据循环时内存耗尽的问题
-
删除MySQL重复数据的方法_MySQL
-
SQL对冗余数据的删除重复记录只保留单条的说明
-
sql2005 数据库转为sql2000数据库的方法(数据导出导入)
-
sqlserver删除表中的重复数据
-
程序写在本机上,数据库在公司里的另外一台电脑上(sqlserver2008),本机上不装任何数据库软件的话,程序能不能连接上数据库
-
具体函数-急,求解 .. 表中有一个关键词字段,现有1000条数据,关键词中不重复的词语。