锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
澶栬繛鎺?
宸﹀榪炴帴
鍙沖榪炴帴
瀹屽叏澶栬繛鎺?
鑷劧榪炴帴
闃呰鍏ㄦ枃
1銆佹煡鎵捐〃涓浣欑殑閲嶅璁板綍錛岄噸澶嶈褰曟槸鏍規嵁鍗曚釜瀛楁錛坧eopleId錛夋潵鍒ゆ柇
select * from people
where peopleId in (select peopleId from people group by peopleId having count (peopleId) > 1)
2銆佸垹闄よ〃涓浣欑殑閲嶅璁板綍錛岄噸澶嶈褰曟槸鏍規嵁鍗曚釜瀛楁錛坧eopleId錛夋潵鍒ゆ柇錛屽彧鐣欐湁rowid鏈灝忕殑璁板綍
delete from people
where peopleId in (select peopleId from people group by peopleId having count (peopleId) > 1)
and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)
3銆佹煡鎵捐〃涓浣欑殑閲嶅璁板綍錛堝涓瓧孌碉級
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having
count(*) > 1)
4銆佸垹闄よ〃涓浣欑殑閲嶅璁板綍錛堝涓瓧孌碉級錛屽彧鐣欐湁rowid鏈灝忕殑璁板綍
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
5銆佹煡鎵捐〃涓浣欑殑閲嶅璁板綍錛堝涓瓧孌碉級錛屼笉鍖呭惈rowid鏈灝忕殑璁板綍
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having
count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
(浜?
姣旀柟璇?br />
鍦ˋ琛ㄤ腑瀛樺湪涓涓瓧孌?#8220;name”錛?br />
鑰屼笖涓嶅悓璁板綍涔嬮棿鐨?#8220;name”鍊兼湁鍙兘浼氱浉鍚岋紝
鐜板湪灝辨槸闇瑕佹煡璇㈠嚭鍦ㄨ琛ㄤ腑鐨勫悇璁板綍涔嬮棿錛?#8220;name”鍊煎瓨鍦ㄩ噸澶嶇殑欏癸紱
Select Name,Count(*) From A Group By Name Having Count(*) > 1
濡傛灉榪樻煡鎬у埆涔熺浉鍚屽ぇ鍒欏涓?
Select Name,sex,Count(*) From A Group By Name,sex Having Count(*) > 1
(涓?
鏂規硶涓
declare @max integer,@id integer
declare cur_rows cursor local for select 涓誨瓧孌?count(*) from 琛ㄥ悕 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 琛ㄥ悕 where 涓誨瓧孌?= @id
fetch cur_rows into @id,@max
end
close cur_rows
set rowcount 0
鏂規硶浜?/p>
鏈変袱涓剰涔変笂鐨勯噸澶嶈褰曪紝涓鏄畬鍏ㄩ噸澶嶇殑璁板綍錛屼篃鍗蟲墍鏈夊瓧孌靛潎閲嶅鐨勮褰曪紝
浜屾槸閮ㄥ垎鍏抽敭瀛楁閲嶅鐨勮褰曪紝姣斿Name瀛楁閲嶅錛岃屽叾浠栧瓧孌典笉涓瀹氶噸澶嶆垨閮介噸澶嶅彲浠ュ拷鐣ャ?/p>
銆銆1銆佸浜庣涓縐嶉噸澶嶏紝姣旇緝瀹規槗瑙e喅錛屼嬌鐢?br /> select distinct * from tableName
銆銆灝卞彲浠ュ緱鍒版棤閲嶅璁板綍鐨勭粨鏋滈泦銆?/p>
銆銆濡傛灉璇ヨ〃闇瑕佸垹闄ら噸澶嶇殑璁板綍錛堥噸澶嶈褰曚繚鐣?鏉★級錛屽彲浠ユ寜浠ヤ笅鏂規硶鍒犻櫎
select distinct * into #Tmp from tableName
drop table tableName
select * into tableName from #Tmp
drop table #Tmp
銆銆鍙戠敓榪欑閲嶅鐨勫師鍥犳槸琛ㄨ璁′笉鍛ㄤ駭鐢熺殑錛屽鍔犲敮涓绱㈠紩鍒楀嵆鍙В鍐熾?/p>
銆銆2銆佽繖綾婚噸澶嶉棶棰橀氬父瑕佹眰淇濈暀閲嶅璁板綍涓殑絎竴鏉¤褰曪紝鎿嶄綔鏂規硶濡備笅
銆銆鍋囪鏈夐噸澶嶇殑瀛楁涓篘ame,Address錛岃姹傚緱鍒拌繖涓や釜瀛楁鍞竴鐨勭粨鏋滈泦
select identity(int,1,1) as autoID, * into #Tmp from tableName
select min(autoID) as autoID into #Tmp2 from #Tmp group by Name,autoID
select * from #Tmp where autoID in(select autoID from #tmp2)
銆銆鏈鍚庝竴涓猻elect鍗沖緱鍒頒簡Name錛孉ddress涓嶉噸澶嶇殑緇撴灉闆嗭紙浣嗗浜嗕竴涓猘utoID瀛楁錛屽疄闄呭啓鏃跺彲浠ュ啓
鍦╯elect瀛愬彞涓渷鍘繪鍒楋級
(鍥?鏌ヨ閲嶅
select * from tablename
where id in (select id from tablename group by id having count(id) > 1)
--from 緗戠粶
http://hi.baidu.com/zeronet/blog/item/27c41046d2c0060a6b63e596.html