最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Oracle去除重復(fù)數(shù)據(jù)

 更新時(shí)間:2022年05月05日 15:39:20   作者:springsnow  
這篇文章介紹了Oracle去除重復(fù)數(shù)據(jù)的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

查詢某些字段相同的記錄

如:查詢col1與col2值相同的記錄:

select a.* from table1 a, table1 b where a.id <> b.id and a.col1 = b.col1 and a.col2 = b.col2;

一、用rowid方法:

根據(jù)oracle自帶的rowid屬性進(jìn)行判斷是否存在重復(fù)記錄。

rowid偽列用于唯一標(biāo)識(shí)物理位置的表行,當(dāng)用insert插入數(shù)據(jù)時(shí),會(huì)自動(dòng)生成rowid,與數(shù)據(jù)一起存放,形如:AAAL=XAAAEAAAAA。

1、查數(shù)據(jù):

select * from    table1 a where rowid!=
(select max(rowid) from table1 b where   a.col1 = b.col1 and a.col2 = b.col2;

2、刪數(shù)據(jù):

保留rowid最大的記錄:

delete  from    table1 a where rowid!=
(select max(rowid) from table1 b where   a.col1 = b.col1 and a.col2 = b.col2;

二、group by 方法:

1、查數(shù)據(jù):

select * from    table1 a where (a.col1,a.col2) in 
(select col1,col2 from  table1 group by  col1,col2 having count(*)>1)

2、刪數(shù)據(jù):

刪除表中多余的重復(fù)記錄(多個(gè)字段),只保留rowid最小的記錄。

delete  from    table1 a where (a.col1,a.col2) in 
(select col1,col2 from  table1 group by  col1,col2 having count(*)>1)
 and rowid not in 
(select min(rowid) from  table1 group by  col1,col2 having count(*)>1)

到此這篇關(guān)于Oracle去除重復(fù)數(shù)據(jù)的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

玉树县| 靖安县| 永寿县| 聂拉木县| 柏乡县| 彩票| 酒泉市| 江都市| 阳泉市| 务川| 拜泉县| 邵阳县| 临高县| 尼木县| 新竹市| 大港区| 桑日县| 沙田区| 鄂温| 林西县| 大城县| 新民市| 林芝县| 林州市| 怀宁县| 德兴市| 霍林郭勒市| 红安县| 来凤县| 扶沟县| 普陀区| 双流县| 陆河县| 屏南县| 南岸区| 石林| 福鼎市| 宣武区| 昭觉县| 精河县| 浠水县|