日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Oracle去除重復數據_oracle

作者:springsnow ? 更新時間: 2022-06-29 編程語言

查詢某些字段相同的記錄

如:查詢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方法:

根據oracle自帶的rowid屬性進行判斷是否存在重復記錄。

rowid偽列用于唯一標識物理位置的表行,當用insert插入數據時,會自動生成rowid,與數據一起存放,形如:AAAL=XAAAEAAAAA。

1、查數據:

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

2、刪數據:

保留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、查數據:

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

2、刪數據:

刪除表中多余的重復記錄(多個字段),只保留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)

原文鏈接:https://www.cnblogs.com/springsnow/p/9394906.html

欄目分類
最近更新