濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > 分享SQL Server刪除重復(fù)行的6個(gè)方法

分享SQL Server刪除重復(fù)行的6個(gè)方法

熱門標(biāo)簽:數(shù)字匠心電銷機(jī)器人 蘭州語音外呼系統(tǒng)運(yùn)營商 如何做地圖標(biāo)注圖鋪 成都電話外呼系統(tǒng)一般多少錢 沒聽見電話機(jī)器人幫你接 陜西電銷外呼系統(tǒng)好用嗎 最新人工智能電銷機(jī)器人 al智能電話機(jī)器人 銀川高頻外呼回?fù)芟到y(tǒng)多少錢
1.如果有ID字段,就是具有唯一性的字段
復(fù)制代碼 代碼如下:

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

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

2. 如果是判斷所有字段也可以這樣
復(fù)制代碼 代碼如下:

select * into #aa from table group by id1,id2,....
delete table
insert into table
select * from #aa

3. 沒有ID的情況
復(fù)制代碼 代碼如下:

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

4. col1+','+col2+','...col5 聯(lián)合主鍵
復(fù)制代碼 代碼如下:

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

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

5.
復(fù)制代碼 代碼如下:

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

6.
復(fù)制代碼 代碼如下:

select distinct * into #temp from tablename
delete tablename
go
insert tablename select * from #temp Sqlclub
go
drop table #temp

以上就是SQL Server刪除重復(fù)行的方法介紹。
您可能感興趣的文章:
  • 刪除DataTable重復(fù)列,只刪除其中的一列重復(fù)行的解決方法
  • sqlserver利用存儲(chǔ)過程去除重復(fù)行的sql語句
  • 刪除Table表中的重復(fù)行的方法
  • SQLServe 重復(fù)行刪除方法
  • 批處理 刪除重復(fù)行的代碼
  • 用vbscript實(shí)現(xiàn)從文本文件中刪除所有重復(fù)行的代碼
  • sql里將重復(fù)行數(shù)據(jù)合并為一行數(shù)據(jù)使用逗號(hào)進(jìn)行分隔

標(biāo)簽:遼源 通化 本溪 邢臺(tái) 鹽城 宜春 巴彥淖爾 朔州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《分享SQL Server刪除重復(fù)行的6個(gè)方法》,本文關(guān)鍵詞  分享,SQL,Server,刪除,重復(fù),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《分享SQL Server刪除重復(fù)行的6個(gè)方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于分享SQL Server刪除重復(fù)行的6個(gè)方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    安顺市| 祁东县| 涟源市| 千阳县| 荥经县| 赣州市| 阜新市| 四会市| 新田县| 兴安县| 河东区| 大渡口区| 晋江市| 河津市| 嘉兴市| 兴安县| 思茅市| 东光县| 瓦房店市| 分宜县| 冷水江市| 兴仁县| 宽城| 诏安县| 亚东县| 会昌县| 塔河县| 家居| 林周县| 连平县| 安阳市| 武夷山市| 会宁县| 华宁县| 涞水县| 潜山县| 榕江县| 沽源县| 南和县| 博客| 车险|