ÍêÈ«Öظ´Êý¾Ý£¬¿ÉÄܵ¼Ö¼ÈëµÈµÈ´íÎó...
    ²éѯÎÞÖظ´½á¹û£º     select distinct * from tableName¡¡     ¾Í¿ÉÒԵõ½ÎÞÖظ´¼Ç¼µÄ½á¹û¼¯¡£ ¡¡¡¡Èç¹û¸Ã±íÐèҪɾ³ýÖظ´µÄ¼Ç¼£¨Öظ´¼Ç¼±£Áô1Ìõ£©£¬¿ÉÒÔ°´ÒÔÏ·½·¨É¾³ý     select distinct * into #tmp from kc_wzmx        delete     from    kc_wzmx      insert     into    kc_wzmx    select     *     from    #tmp      kc_wzmxΪ±íÃû£¬·¢ÉúÕâÖÖÖظ´µÄÔÒòÊDZíÉè¼Æ²»ÖܲúÉúµÄ£¬Ôö¼ÓΨһË÷ÒýÁм´¿É½â¾ö¡£
²éѯ£¬Áгöhtfphm_¡¢gg_ºÍkbh_Èý¸ö×Ö¶ÎÍêÈ«Öظ´µÄÊý¾Ý£»
select  * from  kc_wzmx aa where (select Count(1) from kc_wzmx where aa.htfphm_=htfphm_ and aa.gg_=gg_ and aa.kbh_=kbh_ )>1
SQL Serverɾ³ý±í¼°É¾³ý±íÖÐÊý¾ÝµÄ·½·¨ ɾ³ý±íµÄT-SQLÓï¾äΪ£º drop table <±íÃû> dropÊǶªÆúµÄÒâ˼£¬drop table±íʾ½«Ò»¸ö±í³¹µ×ɾ³ýµô¡£
ɾ³ý±íÊý¾ÝÓÐÁ½ÖÖ·½·¨£ºdeleteºÍtruncate¡£ deleteµÄÓ÷¨ÈçÏ£º delete from <±íÃû> [whereÌõ¼þ] truncateµÄÓ÷¨ÈçÏ£º truncate table <±íÃû> deleteºÍtruncateµÄÇø±ðÈçÏ£º 1¡¢delete¿ÉÒÔɾ³ý±íÖеÄÒ»Ìõ»ò¶àÌõÊý¾Ý£¬Ò²¿ÉÒÔɾ³ýÈ«²¿Êý¾Ý£»¶øtruncateÖ»Äܽ«±íÖеÄÈ«²¿Êý¾Ýɾ³ý¡£ 2¡¢deleteɾ³ý±íÊý¾Ýºó£¬±êʶ×ֶβ»Äܸ´Óá£Ò²¾ÍÊÇ˵Èç¹ûÄã°Ñid=10£¨¼ÙÈçidÊDZêʶ×ֶΣ©µÄÄÇÐÐÊý¾Ýɾ³ýÁË£¬ÄãÒ²²»¿ÉÄÜÔÙ²åÈëÒ»ÌõÊý¾ÝÈÃid=10. 3¡¢truncateɾ³ý±íÊý¾Ýºó£¬±êʶÖØлָ´³õʼ״̬¡£Ä¬ÈÏΪ³õʼֵΪ1£¬Ò²¾ÍÊÇ˵£¬truncateÖ®ºó£¬ÔÙ²åÈëÒ»ÌõÊý¾Ý£¬id=1.
ÆäËü»¥ÁªÍøÕª³£º
1¡¢Ð´Ò»ÕűíÖÐÓÐidºÍname Á½¸ö×ֶΣ¬²éѯ³önameÖظ´µÄËùÓÐÊý¾Ý£¬ÏÖÔÚÁÐÏ£º select * from xi a where (a.username) in  (select username from xi group by username  having count(*) > 1) 2¡¢²éѯ³öËùÓÐÊý¾Ý½øÐзÖ×éÖ®ºó£¬ºÍÖظ´Êý¾ÝµÄÖظ´´ÎÊýµÄ²éѯÊý¾Ý£¬ÏÈÁÐÏ£º select  count(username) as ¡¯Öظ´´ÎÊý¡¯,username from xi group by username  having count(*)>1 order by username desc 3¡¢Ò»ÏÂΪ ²é¿´±ðÈ˵Ġ½á¹û£¬ÏÖÁÐÏ£º²éѯ¼°É¾³ýÖظ´¼Ç¼µÄ·½·¨´óÈ«
1¡¢²éÕÒ±íÖжàÓàµÄÖظ´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ¥¸ö×ֶΣ¨peopleId£©À´ÅжÏselect * from people where peopleId in (select  peopleId  from  people  group  by  peopleId  having  count(peopleId) > 1)
2¡¢É¾³ý±íÖжàÓàµÄÖظ´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ¥¸ö×ֶΣ¨peopleId£©À´Åжϣ¬Ö»ÁôÓÐ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)
(¶þ) ±È·½Ëµ ÔÚA±íÖдæÔÚÒ»¸ö×ֶΡ°name¡±£¬ ¶øÇÒ²»Í¬¼Ç¼֮¼äµÄ¡°name¡±ÖµÓпÉÄÜ»áÏàͬ£¬ ÏÖÔÚ¾ÍÊÇÐèÒª²éѯ³öÔڸñíÖеĸ÷¼Ç¼֮¼ä£¬¡°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 integerdeclare cur_rows cursor local for select Ö÷×Ö¶Î,count(*) from ±íÃû group by Ö÷×ֶΠhaving count(*) >£» 1open cur_rowsfetch cur_rows into @id,@maxwhile @@fetch_status=0beginselect @max = @max -1set rowcount @maxdelete from ±íÃû where Ö÷×ֶΠ= @idfetch cur_rows into @id,@maxendclose cur_rowsset rowcount 0
·½·¨¶þ£¢Öظ´¼Ç¼£¢ÓÐÁ½¸öÒâÒåÉϵÄÖظ´¼Ç¼£¬Ò»ÊÇÍêÈ«Öظ´µÄ¼Ç¼£¬Ò²¼´ËùÓÐ×ֶξùÖظ´µÄ¼Ç¼£¬¶þÊDz¿·Ö¹Ø¼ü×Ö¶ÎÖظ´µÄ¼Ç¼£¬±ÈÈçName×Ö¶ÎÖظ´£¬¶øÆäËû×ֶβ»Ò»¶¨Öظ´»ò¶¼Öظ´¿ÉÒÔºöÂÔ¡£
¡¡¡¡1¡¢¶ÔÓÚµÚÒ»ÖÖÖظ´£¬±È½ÏÈÝÒ×½â¾ö£¬Ê¹ÓÃselect distinct * from tableName¡¡¡¡¾Í¿ÉÒԵõ½ÎÞÖظ´¼Ç¼µÄ½á¹û¼¯¡£¡¡¡¡Èç¹û¸Ã±íÐèҪɾ³ýÖظ´µÄ¼Ç¼£¨Öظ´¼Ç¼±£Áô1Ìõ£©£¬¿ÉÒÔ°´ÒÔÏ·½·¨É¾³ýselect distinct * into #Tmp from tableNamedrop table tableNameselect * into tableName from #Tmpdrop table #Tmp¡¡¡¡·¢ÉúÕâÖÖÖظ´µÄÔÒòÊDZíÉè¼Æ²»ÖܲúÉúµÄ£¬Ôö¼ÓΨһË÷ÒýÁм´¿É½â¾ö¡£
¡¡¡¡2¡¢ÕâÀàÖظ´ÎÊÌâͨ³£ÒªÇó±£ÁôÖظ´¼Ç¼ÖеĵÚÒ»Ìõ¼Ç¼£¬²Ù×÷·½·¨ÈçÏ¡¡¡¡¼ÙÉèÓÐÖظ´µÄ×Ö¶ÎΪName,Address£¬ÒªÇóµÃµ½ÕâÁ½¸ö×Ö¶ÎΨһµÄ½á¹û¼¯select identity(int,1,1) as autoID, * into #Tmp from tableNameselect min(autoID) as autoID into #Tmp2 from #Tmp group by Name,autoIDselect * from #Tmp where autoID in(select autoID from #tmp2)¡¡¡¡×îºóÒ»¸öselect¼´µÃµ½ÁËName£¬Address²»Öظ´µÄ½á¹û¼¯£¨µ«¶àÁËÒ»¸öautoID×ֶΣ¬Êµ¼Êдʱ¿ÉÒÔдÔÚselect×Ó¾äÖÐÊ¡È¥´ËÁУ©
(ËÄ) ²éѯÖظ´select * from tablename where id in (select id from tablenamegroup by idhaving count(id) > 1)
*******¾ÙÀý*********
²éѯ Sap Business OneÖÆÔìÉÌOMRC±íÖÐÖظ´Êý¾Ý(Pass) select * from omrc where firmname in (select  firmname  from  omrc  group  by  firmname  having  count(firmname) > 1)
ɾ³ý Sap Business OneÖÆÔìÉÌOMRC±íÖÐÖظ´Êý¾Ý(Pass) delete from omrc where FirmName  in (select  FirmName  from omrc  group  by  FirmName   having  count(FirmName) > 1) and FirmCode not in (select min(FirmCode) from  omrc  group by FirmName  having count(FirmName )>1)
OMRCΪ±íÃû£¬FirmName/FirmCodeΪ×Ö¶ÎÃû¡£
***ɾ³ý»ò±£ÁôһЩÐÐÊý¾Ý
Êý¾Ý¿âint001¼¸¸ö±íOMRC/POR1/RDR1£¬±£ÁôÇ°ÁùÐÐÊý¾Ý(²Ù×÷£¬³öÏÖ±í´íÎ󣬴¦Àíºó/truncate/ÔÙµ¼Èë) DELETE OMRC WHERE FirmCode NOT IN(SELECT TOP 6 FirmCode FROM OMRC) DELETE Por1 WHERE DocEntry NOT IN(SELECT TOP 6 DocEntry FROM Por1) DELETE RDR1 WHERE DocEntry NOT IN(SELECT TOP 6 DocEntry FROM RDR1)
 
*****************************
²éѯÊý¾Ý¿âÖдøÓÐij¸ö×ֶεÄËùÓбíÃû
MySQLÊý¾Ý¿â²éѯ´øÓÐij¸ö×ֶεÄËùÓбíÃû£º
£¨1£©¾«È·²éѯÓï¾äÈçÏ£º
SELECT * FROM information_schema.columns WHERE column_name=¡¯column_name¡¯
£¨2£©Ä£ºýÆ¥Åä²éѯ
SELECT * FROM information_schema.columns WHERE column_name LIKE ¡¯%column_name%¡¯
OracleÊý¾Ý¿â²éѯ´øÓÐij¸ö×ֶεÄËùÓбíÃû£º
£¨1£©¾«È·²éѯÓï¾äÈçÏ£º
SELECT column_name,table_name FROM user_tab_columns WHERE column_name=¡¯column_name¡¯
£¨2£©Ä£ºýÆ¥Åä²éѯ
SELECT column_name,table_name,FROM user_tab_columns WHERE column_name LIKE ¡¯%column_name%¡¯
SQLServerÊý¾Ý¿â²éѯ´øÓÐij¸ö×ֶεÄËùÓбíÃû£º
£¨1£©¾«È·²éѯÓï¾äÈçÏ£º
SELECT [name] FROM [¿âÃû].[dbo].sysobjects WHERE id IN (SELECT id FROM [¿âÃû].[dbo].syscolumns WHERE name = ¡¯×Ö¶ÎÃû¡¯)
£¨2£©Ä£ºýÆ¥Åä²éѯ
SELECT [name] FROM [¿âÃû].[dbo].sysobjects WHERE id IN (SELECT id FROM [¿âÃû].[dbo].syscolumns WHERE name LIKE ¡¯%×Ö¶ÎÃû%¡¯)
 
  |