Oracle:
删除数据库中重复记录
select corpname,count(*) from tbcorp group by corpname having count(*) > 1
delete from tbcorp a where a.rowid!=(select min(b.rowid) from tbcorp b where a.corpname = b.corpname)
应用到地调院的项目后有如下的SQL语句:
select BlockID,NodeNO, count(*) from Geop group by BlockID,NodeNo having count(*)>1
查出重复的点,通过两个条件来判断。。。
以下用来删除数据库中重复记录,但保留一条记录;
第一种方法:
/*先把唯一的記錄保存下來,SQL Server 2000支持 Table變量*/
DECLARE @rsTemp table(Code int,CodeRule Varchar(50))
INSERT INTO @rsTemp Select DISTINCT Code,CodeRule From a
/*殺掉全部記錄*/
DELETE From a
/*重新插資料進去*/
INSERT INTO a Select * From @rsTemp
第二种方法:
delete tablename from (select pk,max(重复字段) as k from tablename group by pk having count(*)>1) as b,tablename where tablename.pk=b.pk and tablename.重复字段
这原来是我blogger上的发的一篇文章,因为blogger要升级,NND,气死人了,升级全部文章得自己重粘一遍,顺便把技术文章全放这边吧!原文章可能参考的是:
http://www.cnblogs.com/wertou/archive/2006/03/29/362214.html
删除数据库中重复记录
select corpname,count(*) from tbcorp group by corpname having count(*) > 1
delete from tbcorp a where a.rowid!=(select min(b.rowid) from tbcorp b where a.corpname = b.corpname)
应用到地调院的项目后有如下的SQL语句:
select BlockID,NodeNO, count(*) from Geop group by BlockID,NodeNo having count(*)>1
查出重复的点,通过两个条件来判断。。。
以下用来删除数据库中重复记录,但保留一条记录;
第一种方法:
/*先把唯一的記錄保存下來,SQL Server 2000支持 Table變量*/
DECLARE @rsTemp table(Code int,CodeRule Varchar(50))
INSERT INTO @rsTemp Select DISTINCT Code,CodeRule From a
/*殺掉全部記錄*/
DELETE From a
/*重新插資料進去*/
INSERT INTO a Select * From @rsTemp
第二种方法:
delete tablename from (select pk,max(重复字段) as k from tablename group by pk having count(*)>1) as b,tablename where tablename.pk=b.pk and tablename.重复字段
这原来是我blogger上的发的一篇文章,因为blogger要升级,NND,气死人了,升级全部文章得自己重粘一遍,顺便把技术文章全放这边吧!原文章可能参考的是:
http://www.cnblogs.com/wertou/archive/2006/03/29/362214.html