自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

SQL Server查找與重復記錄的刪除方案描述

數(shù)據(jù)庫 SQL Server
我們今天主要向大家描述的是SQL Server查找與刪除重復記錄的實際操作方法,以及在其實際操作中我們大家要用到的相關代碼的描述。

此文章主要向大家介紹的是SQL Server查找與刪除重復記錄的實際操作方法,你是否對如何正確查出字段dd中有重復的記錄的實際操作有不解之處?即要知道哪些記錄是重復的,怎么弄?

執(zhí)行:

 

  1. select dd,count(*) from table group by dd having count(*)>

如何用sql 查找兩個字段重復的記錄,并列出重復記錄

表名為CJB, 列出其中XH和KCMC字段都重復的記錄

 

執(zhí)行:

 

  1. select * from CJB a join (  
  2. select XH,KCMC from CJB group by XH,KCMC  
  3. having count(*)>1) b on a.XH=b.XH and a.KCMC=b.KCMC order by   
  4. a.KCMC ,a.XH 

實例:

  1. select productID,searchkay from shortkay group by searchkay,productID having count(*) > 1 order by searchkay  

 

等同于下面這句:

 

  1. select a.ID,a.productID,a.searchkay from shortkay a join (select productID,searchkay from shortkay group by productID,  
  2. searchkay having count(*)>1) b on a.productID=b.productID and a.searchkay=b.searchkay order by a.searchkay, a.productID  

1、SQL Server查找表中多余的重復記錄,重復記錄是根據(jù)單個字段(peopleId)來判斷

  1. select * from people  
  2. where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) 

2、刪除表中多余的重復記錄,重復記錄是根據(jù)單個字段(peopleId)來判斷,只留有rowid最小的記錄

  1. delete from people   
  2. where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)  
  3. and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>

)

3、查找表中多余的重復記錄(多個字段)

  1. select * from vitae a  
  2. where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1) 

4、刪除表中多余的重復記錄(多個字段),只留有rowid最小的記錄

  1. delete from vitae a  
  2. where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)  
  3. and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1) 

5、SQL Server查找表中多余的重復記錄(多個字段),不包含rowid最小的記錄

  1. select * from vitae a  
  2. where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)  
  3. and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1) 

 

以上的相關內(nèi)容就是對SQL Server查找和刪除重復記錄的方法的介紹,望你能有所收獲。

 

【編輯推薦】

  1. SQL Server數(shù)據(jù)庫相關數(shù)據(jù)大匯和
  2. 快速對SQL Server鎖機制進行掌握的竅門
  3. SQL Server存儲圖像數(shù)據(jù)大閱兵
  4. SQL Server復制和其相關的工作原理
  5. SQL Server重復數(shù)據(jù)刪除的2個操作方案

     

     
責任編輯:佚名 來源: 電子工業(yè)出版社
相關推薦

2010-09-25 16:17:25

SQL語句

2011-03-21 17:25:08

SQL Server數(shù)重復記錄

2011-05-24 10:04:39

Oracle重復記錄

2010-09-28 15:46:22

SQL刪除重復記錄

2010-09-28 15:40:51

SQL刪除重復記錄

2010-10-13 17:07:46

MySQL刪除重復記錄

2010-09-03 09:49:39

SQL刪除

2010-11-23 14:26:02

MySQL刪除重復記錄

2010-10-27 16:49:23

Oracle刪除重復記

2010-07-02 13:50:11

SQL Server數(shù)

2010-09-03 11:42:04

SQL刪除

2010-10-27 16:56:05

Oracle重復記錄

2010-09-30 10:29:56

DB2刪除重復記錄

2010-10-13 17:13:17

MySQL重復記錄

2010-11-25 15:43:02

MYSQL查詢重復記錄

2010-07-08 13:06:05

SQL Server刪

2010-07-21 11:38:59

SQL Server重

2010-07-26 09:55:55

SQL Server重

2010-07-23 15:09:42

SQL Server刪

2010-07-23 16:21:37

SQL Server重
點贊
收藏

51CTO技術棧公眾號