復(fù)制代碼 代碼如下:
delete WeiBoTopics where Id in(select max(Id) from WeiBoTopics group by WeiBoId,Title having COUNT(*) > 1);
SQL:刪除重復(fù)數(shù)據(jù),只保留一條用SQL語(yǔ)句,刪除掉重復(fù)項(xiàng)只保留一條在幾千條記錄里,存在著些相同的記錄,如何能用SQL語(yǔ)句,刪除掉重復(fù)的呢
1、查找表中多余的重復(fù)記錄,重復(fù)記錄是根據(jù)單個(gè)字段(peopleId)來(lái)判斷
復(fù)制代碼 代碼如下:
select * from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
2、刪除表中多余的重復(fù)記錄,重復(fù)記錄是根據(jù)單個(gè)字段(peopleId)來(lái)判斷,只留有rowid最小的記錄
復(fù)制代碼 代碼如下:
delete from people where peopleName in (select peopleName from people group by peopleName having count(peopleName) > 1) and peopleId not in (select min(peopleId) from people group by peopleName having count(peopleName)>1)
3、查找表中多余的重復(fù)記錄(多個(gè)字段)
復(fù)制代碼 代碼如下:
select * from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
4、刪除表中多余的重復(fù)記錄(多個(gè)字段),只留有rowid最小的記錄
復(fù)制代碼 代碼如下:
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、查找表中多余的重復(fù)記錄(多個(gè)字段),不包含rowid最小的記錄
復(fù)制代碼 代碼如下:
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)
6.消除一個(gè)字段的左邊的第一位:
復(fù)制代碼 代碼如下:
update tableName set [Title]=Right([Title],(len([Title])-1)) where Title like '村%'
7.消除一個(gè)字段的右邊的第一位:
復(fù)制代碼 代碼如下:
update tableName set [Title]=left([Title],(len([Title])-1)) where Title like '%村'
8.假刪除表中多余的重復(fù)記錄(多個(gè)字段),不包含rowid最小的記錄
復(fù)制代碼 代碼如下:
update vitae set ispass=-1 where peopleId in (select peopleId from vitae group by peopleId,seq having count(*) > 1) and seq in (select 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)
您可能感興趣的文章:- Mysql一些復(fù)雜的sql語(yǔ)句(查詢與刪除重復(fù)的行)
- 使用SQL批量替換語(yǔ)句修改、增加、刪除字段內(nèi)容
- 必須會(huì)的SQL語(yǔ)句(四) 數(shù)據(jù)刪除和更新
- 必須會(huì)的SQL語(yǔ)句(二) 創(chuàng)建表、修改表結(jié)構(gòu)、刪除表
- 使用sql語(yǔ)句創(chuàng)建和刪除約束示例代碼
- oracle使用sql語(yǔ)句增加字段示例(sql刪除字段語(yǔ)句)
- MySQL中批量刪除指定前綴表的sql語(yǔ)句
- SQL語(yǔ)句刪除和添加外鍵、主鍵的方法
- MySQL刪除數(shù)據(jù)Delete與Truncate語(yǔ)句使用比較
- 簡(jiǎn)單了解SQL常用刪除語(yǔ)句原理區(qū)別