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

用SQL語(yǔ)句,熟練使用刪除語(yǔ)句

申請(qǐng)免費(fèi)試用、咨詢電話:400-8352-114

  用SQL語(yǔ)句,刪除掉重復(fù)項(xiàng)只保留一條

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

2、刪除表中多余的重復(fù)記錄,重復(fù)記錄是根據(jù)單個(gè)字段(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、查找表中多余的重復(fù)記錄(多個(gè)字段)
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最小的記錄
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最小的記錄
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è)字段的左邊的第一位:

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

7.消除一個(gè)字段的右邊的第一位:

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

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




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

泛普入庫(kù)出庫(kù)管理軟件其他應(yīng)用

藥品進(jìn)銷存管理系統(tǒng) 醫(yī)藥進(jìn)銷存 超市進(jìn)銷存管理系統(tǒng) 服裝進(jìn)銷存軟件 倉(cāng)庫(kù)進(jìn)銷存管理軟件 進(jìn)銷存財(cái)務(wù)軟件 傻瓜進(jìn)銷存 萬(wàn)能進(jìn)銷存軟件 進(jìn)銷存網(wǎng)絡(luò)版 進(jìn)銷存管理系統(tǒng) 進(jìn)銷存系統(tǒng) 服裝庫(kù)存管理軟件 條碼倉(cāng)庫(kù)管理軟件 庫(kù)存管理軟件 倉(cāng)庫(kù)管理軟件 庫(kù)房管理軟件 出入庫(kù)管理軟件 倉(cāng)儲(chǔ)管理系統(tǒng) 倉(cāng)庫(kù)管理系統(tǒng) 庫(kù)存管理系統(tǒng) 入庫(kù)出庫(kù)管理軟件 進(jìn)銷存軟件排名 倉(cāng)庫(kù)管理軟件哪個(gè)好