監(jiān)理公司管理系統(tǒng) | 工程企業(yè)管理系統(tǒng) | OA系統(tǒng) | ERP系統(tǒng) | 造價咨詢管理系統(tǒng) | 工程設計管理系統(tǒng) | 簽約案例 | 購買價格 | 在線試用 | 手機APP | 產(chǎn)品資料
X 關閉

用SQL語句,熟練使用刪除語句

申請免費試用、咨詢電話:400-8352-114

  用SQL語句,刪除掉重復項只保留一條

在幾千條記錄里,存在著些相同的記錄,如何能用SQL語句,刪除掉重復的呢
1、查找表中多余的重復記錄,重復記錄是根據(jù)單個字段(peopleId)來判斷
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)

2、刪除表中多余的重復記錄,重復記錄是根據(jù)單個字段(peopleId)來判斷,只留有rowid最小的記錄
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、查找表中多余的重復記錄(多個字段)
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

4、刪除表中多余的重復記錄(多個字段),只留有rowid最小的記錄
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、查找表中多余的重復記錄(多個字段),不包含rowid最小的記錄
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.消除一個字段的左邊的第一位:

update tableName set [Title]=Right([Title],(len([Title])-1)) where Title like '村%'

7.消除一個字段的右邊的第一位:

update tableName set [Title]=left([Title],(len([Title])-1)) where Title like '%村'

8.假刪除表中多余的重復記錄(多個字段),不包含rowid最小的記錄
update vitae set ispass=-1
where peopleId in (select peopleId from vitae group by peopleId




發(fā)布:2007-04-16 17:21    編輯:泛普軟件 · xiaona    [打印此頁]    [關閉]

泛普入庫出庫管理軟件其他應用

藥品進銷存管理系統(tǒng) 醫(yī)藥進銷存 超市進銷存管理系統(tǒng) 服裝進銷存軟件 倉庫進銷存管理軟件 進銷存財務軟件 傻瓜進銷存 萬能進銷存軟件 進銷存網(wǎng)絡版 進銷存管理系統(tǒng) 進銷存系統(tǒng) 服裝庫存管理軟件 條碼倉庫管理軟件 庫存管理軟件 倉庫管理軟件 庫房管理軟件 出入庫管理軟件 倉儲管理系統(tǒng) 倉庫管理系統(tǒng) 庫存管理系統(tǒng) 入庫出庫管理軟件 進銷存軟件排名 倉庫管理軟件哪個好