成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

總結(jié):六種刪除數(shù)據(jù)庫(kù)重復(fù)行的方法

數(shù)據(jù)庫(kù)
SQL Server刪除重復(fù)行是我們最常見的操作之一,下面就為您介紹六種適合不同情況的SQL Server刪除重復(fù)行的方法,供您參考。

SQL Server刪除重復(fù)行是我們最常見的操作之一,下面就為您介紹六種適合不同情況的SQL Server刪除重復(fù)行的方法,供您參考。

1.如果有ID字段,就是具有唯一性的字段

  1. delect   table   where   id   not   in   (      
  2.   
  3. select   max(id)   from   table   group   by   col1,col2,col3...      
  4. )      

group by 子句后跟的字段就是你用來(lái)判斷重復(fù)的條件,如只有col1,那么只要col1字段內(nèi)容相同即表示記錄相同。

2. 如果是判斷所有字段也可以這樣

  1. select   *   into   #aa   from   table   group   by   id1,id2,....      
  2. delete   table        
  3. insert   into   table        
  4. select   *   from   #aa  

3. 沒有ID的情況

  1. select   identity(int,1,1)   as   id,*   into   #temp   from   tabel      
  2. delect   #   where   id   not   in   (      
  3. select   max(id)   from   #   group   by   col1,col2,col3...)      
  4. delect   table      
  5. inset   into   table(...)      
  6. select   .....   from   #temp  

4. col1+','+col2+','...col5 聯(lián)合主鍵

  1. select   *   from     table   where   col1+','+col2+','...col5   in   (      
  2. select   max(col1+','+col2+','...col5)   from   table        
  3. where   having   count(*)>1      
  4. group   by   col1,col2,col3,col4        
  5. )   

group by 子句后跟的字段就是你用來(lái)判斷重復(fù)的條件,如只有col1,那么只要col1字段內(nèi)容相同即表示記錄相同。

5.

  1. select   identity(int,1,1)   as   id,*   into   #temp   from   tabel      
  2. select   *   from     #temp   where   id   in   (      
  3. select   max(id)   from   #emp   where   having   count(*)>1   group   by   col1,col2,col3...)     

6.

  1. select   distinct   *   into   #temp   from   tablename        
  2. delete   tablename        
  3. go      
  4. insert   tablename   select   *   from   #temp   Sqlclub    
  5. go      
  6. drop   table   #temp  

原文鏈接:http://www.cnblogs.com/zhangshufeng/archive/2011/09/05/2167079.html

【編輯推薦】

  1. 養(yǎng)成一個(gè)SQL好習(xí)慣帶來(lái)一筆大財(cái)富
  2. 告訴你,如何成就DBA職業(yè)生涯
  3. SQL Server性能調(diào)優(yōu)之淺析SQL執(zhí)行的過(guò)程
  4. 客戶的一次疏忽,DBA的一次噩夢(mèng)
  5. 數(shù)據(jù)庫(kù)點(diǎn)滴之精妙SQL語(yǔ)句

 

 

 

責(zé)任編輯:艾婧 來(lái)源: 自 慎的博客
相關(guān)推薦

2010-10-22 16:29:11

SQL Server刪

2022-05-25 09:55:40

數(shù)據(jù)重復(fù)提交Java

2011-07-28 16:39:03

MySQL數(shù)據(jù)庫(kù)修改MySQL密碼

2011-03-08 08:59:01

SQL Server數(shù)數(shù)據(jù)移動(dòng)

2011-01-12 21:26:49

2017-10-27 11:47:05

SQL數(shù)據(jù)庫(kù)優(yōu)化

2011-05-24 10:54:15

數(shù)據(jù)庫(kù)重復(fù)數(shù)據(jù)刪除

2019-05-06 15:27:48

Oracle數(shù)據(jù)庫(kù)數(shù)據(jù)

2019-05-16 13:00:18

異步編程JavaScript回調(diào)函數(shù)

2018-04-27 13:00:00

數(shù)據(jù)庫(kù)MySQL刪除重復(fù)行

2023-09-06 08:00:00

ChatGPT數(shù)據(jù)分析

2023-08-15 15:44:55

React開發(fā)

2011-02-24 10:56:34

人才

2023-06-01 16:45:11

React開發(fā)JavaScript

2010-04-13 10:15:17

Oracle數(shù)據(jù)庫(kù)

2025-05-19 00:02:00

數(shù)據(jù)脫敏加密算法數(shù)據(jù)庫(kù)

2020-10-27 10:33:01

物聯(lián)網(wǎng)

2016-09-01 14:04:51

數(shù)據(jù)中心

2010-10-08 11:13:22

MySQL修改密碼

2020-12-15 10:54:22

物聯(lián)網(wǎng)互聯(lián)網(wǎng)IoT
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 91社区在线观看播放 | 亚洲一区二区三区欧美 | 免费人成在线观看网站 | 日韩一区二区在线视频 | av一区二区在线观看 | 成人精品免费视频 | 色婷婷国产精品 | 亚洲高清视频在线 | 国产精品自在线 | 欧美一级在线观看 | 超碰美女在线 | 国产一级一级 | 女人牲交视频一级毛片 | 国内自拍偷拍一区 | 亚洲www| 成人在线国产 | 一区免费| 91干b| 天天综合网7799精品 | 在线观看国产视频 | 久久高清 | 欧美精品在线免费 | 欧美一级免费 | 99pao成人国产永久免费视频 | 精品国产乱码久久久久久88av | 久久的色| 欧美日韩中文字幕 | 亚洲成人久久久 | 欧美日韩高清在线观看 | 在线成人www免费观看视频 | 久久国产精彩视频 | 欧美一区二区三区在线看 | 成人免费观看男女羞羞视频 | 毛片免费视频 | 欧美亚洲国语精品一区二区 | 欧美日韩亚洲国产 | 国产精品高潮呻吟久久av黑人 | 久久久精品视频一区二区三区 | 高清久久 | 国产色在线 | 成人在线免费视频 |