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

MySQL數(shù)據(jù)庫如何刪除表中部分關(guān)鍵字段重復(fù)的記錄

數(shù)據(jù)庫 MySQL
本文我們通過一個(gè)例子介紹了MySQL數(shù)據(jù)庫刪除表中部分關(guān)鍵字段重復(fù)的記錄的方法,希望能夠?qū)δ兴鶐椭?/div>

MySQL數(shù)據(jù)庫中如何刪除部分關(guān)鍵字段重復(fù)的記錄呢?本文我們通過一個(gè)例子來介紹這一刪除方法,接下來我們先說一說這個(gè)例子。

首先看一下Statistic表結(jié)構(gòu):

MySQL數(shù)據(jù)庫如何刪除表中部分關(guān)鍵字段重復(fù)的記錄

處理樣本:

MySQL數(shù)據(jù)庫如何刪除表中部分關(guān)鍵字段重復(fù)的記錄

主要實(shí)現(xiàn)目的:

刪除Date Server Item SubItem 完全相同,Id肯定不同,Value可能相同的記錄。

比如:

 2011-07-27 | mx1.dns.com.cn | SEND_MAIL | TOTAL| 14522 |          | 229  【刪除】

 2011-07-27 | mx1.dns.com.cn | SEND_MAIL | TOTAL| 14795 |          | 248  【保留】

實(shí)現(xiàn)過程:

***步:創(chuàng)建與Statistic表結(jié)構(gòu)完全相同的臨時(shí)表。

  1. use Statistic;  
  2.  
  3. create table s_tmp as select * from Statistic where 1=2

第二步:根據(jù)Id(自動(dòng)增長)提取較新數(shù)據(jù)到臨時(shí)表

  1. insert into s_tmp select a.* from Statistic a,Statistic b where   
  2.  
  3. a.Date=b.Date and a.Server=b.Server and a.Key=b.Key and a.SubKey=b.SubKey and a.id > b.id; 

第三步:根據(jù)臨時(shí)表里的數(shù)據(jù)的日期信息,將原表的對(duì)應(yīng)日期的數(shù)據(jù)刪除

  1. delete  from Statistic where Date in (select distinct Date  from s_tmp ); 

第四步:將臨時(shí)表里的數(shù)據(jù)導(dǎo)入Statistic

  1. insert into Statistic select * from  s_tmp; 

第五步:***清空臨時(shí)表

  1. delete * from s_tmp; 

實(shí)現(xiàn)結(jié)果:(去重后)

MySQL數(shù)據(jù)庫如何刪除表中部分關(guān)鍵字段重復(fù)的記錄

關(guān)于刪除MySQL表部分關(guān)鍵字段重復(fù)的方法就介紹到這里了,如果您想了解更多關(guān)于MySQL數(shù)據(jù)庫的知識(shí),可以到這里看一下:http://database.51cto.com/mysql/,相信一定能夠帶給您收獲的。

【編輯推薦】

  1. MySQL數(shù)據(jù)庫命令行常用命令大全總結(jié)篇
  2. MySQL數(shù)據(jù)庫如何實(shí)現(xiàn)跨表更新與數(shù)據(jù)并合
  3. MySQL數(shù)據(jù)庫修改MySQL密碼的六種措施總結(jié)
  4. 關(guān)于MySQL數(shù)據(jù)庫創(chuàng)建內(nèi)存表時(shí)的一些注意事項(xiàng)
  5. 關(guān)于MySQL數(shù)據(jù)庫修改root用戶使其遠(yuǎn)程登錄的說明
責(zé)任編輯:趙鵬 來源: CSDN博客
相關(guān)推薦

2018-09-11 17:13:23

MySQ數(shù)據(jù)庫重復(fù)記錄

2018-04-27 13:00:00

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

2011-03-04 17:30:42

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

2010-04-13 10:23:40

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

2010-10-08 15:49:09

Mysql更新字段

2019-08-19 14:06:27

MySQLDocker數(shù)據(jù)庫

2010-09-26 17:24:24

SQL字符串

2011-05-17 11:23:02

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

2010-07-02 13:50:11

SQL Server數(shù)

2010-04-28 18:25:51

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

2011-03-29 09:26:35

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

2021-01-26 13:40:44

mysql數(shù)據(jù)庫

2009-01-11 17:32:03

Oracle數(shù)據(jù)庫重復(fù)數(shù)據(jù)

2010-10-13 17:07:46

MySQL刪除重復(fù)記錄

2010-04-13 10:15:17

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

2022-01-17 08:36:46

MySQLAmazon RDS 數(shù)據(jù)庫

2011-05-24 14:13:20

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

2009-02-02 13:16:23

修復(fù)數(shù)據(jù)表MySQL

2011-05-18 13:16:21

MySQL數(shù)據(jù)庫鎖定

2011-04-06 17:35:17

Access數(shù)據(jù)庫空記錄
點(diǎn)贊
收藏

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