測試去除重複資料
1、建立測試表,初始化資料
JZH@jzh>create table t (x number,y number);
Table created.
JZH@jzh>insert into t values (1,1);
1 row created.
JZH@jzh>insert into t values (1,1);
1 row created.
JZH@jzh>insert into t values (2,2);
1 row created.
JZH@jzh>commit;
Commit complete.
JZH@jzh>select * from t;
X Y
---------- ----------
1 1
1 1
2 2
2、使用distinct方法
JZH@jzh>select distinct x,y from t;
X Y
---------- ----------
1 1
2 2
3、使用group by方法
JZH@jzh>select x,y from t where (x,y) in (select x,y from t group by x,y having count(*)>1);
X Y
---------- ----------
1 1
1 1
4、使用rowid方法
1)查重
JZH@jzh>JZH@jzh>select * from t a where a.rowid <> (select max(rowid) from t b where a.x=b.x and a.y=b.y);
X Y
---------- ----------
1 1
JZH@jzh>select * from t a where a.rowid <> (select min(rowid) from t b where a.x=b.x and a.y=b.y);
X Y
---------- ----------
1 1
2)去重
JZH@jzh>delete from t a where a.rowid<>(select max(rowid) from t b where a.x=b.x and a.y=b.y);
1 row deleted.
JZH@jzh>commit;
Commit complete.
JZH@jzh>select * from t;
X Y
---------- ----------
1 1
2 2
5、使用分析函式方法
1)查重
JZH@jzh>select a.x,a.y,row_number () over (partition by a.x,a.y order by a.rowid) rn from t a;
X Y RN
---------- ---------- ----------
1 1 1
1 1 2
2 2 1
JZH@jzh>select b.x,b.y from (select a.x,a.y,row_number () over (partition by a.x,a.y order by a.rowid) rn from t a) b where b.rn>1;
X Y
---------- ----------
1 1
2)去重
JZH@jzh>delete from t where rowid in (select rowid from (select a.x,a.y,row_number () over (partition by a.x,a.y order by a.rowid) rn from t a) b where rn>1);
1 row deleted.
JZH@jzh>select * from t;
X Y
---------- ----------
1 1
2 2
JZH@jzh>create table t (x number,y number);
Table created.
JZH@jzh>insert into t values (1,1);
1 row created.
JZH@jzh>insert into t values (1,1);
1 row created.
JZH@jzh>insert into t values (2,2);
1 row created.
JZH@jzh>commit;
Commit complete.
JZH@jzh>select * from t;
X Y
---------- ----------
1 1
1 1
2 2
2、使用distinct方法
JZH@jzh>select distinct x,y from t;
X Y
---------- ----------
1 1
2 2
3、使用group by方法
JZH@jzh>select x,y from t where (x,y) in (select x,y from t group by x,y having count(*)>1);
X Y
---------- ----------
1 1
1 1
4、使用rowid方法
1)查重
JZH@jzh>JZH@jzh>select * from t a where a.rowid <> (select max(rowid) from t b where a.x=b.x and a.y=b.y);
X Y
---------- ----------
1 1
JZH@jzh>select * from t a where a.rowid <> (select min(rowid) from t b where a.x=b.x and a.y=b.y);
X Y
---------- ----------
1 1
2)去重
JZH@jzh>delete from t a where a.rowid<>(select max(rowid) from t b where a.x=b.x and a.y=b.y);
1 row deleted.
JZH@jzh>commit;
Commit complete.
JZH@jzh>select * from t;
X Y
---------- ----------
1 1
2 2
5、使用分析函式方法
1)查重
JZH@jzh>select a.x,a.y,row_number () over (partition by a.x,a.y order by a.rowid) rn from t a;
X Y RN
---------- ---------- ----------
1 1 1
1 1 2
2 2 1
JZH@jzh>select b.x,b.y from (select a.x,a.y,row_number () over (partition by a.x,a.y order by a.rowid) rn from t a) b where b.rn>1;
X Y
---------- ----------
1 1
2)去重
JZH@jzh>delete from t where rowid in (select rowid from (select a.x,a.y,row_number () over (partition by a.x,a.y order by a.rowid) rn from t a) b where rn>1);
1 row deleted.
JZH@jzh>select * from t;
X Y
---------- ----------
1 1
2 2
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10271187/viewspace-1719676/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mongodb如何去除重複資料MongoDB
- mongodb去除重複的資料MongoDB
- 資料處理之去除重複資料
- php資料庫資料如何去除重複資料呢?PHP資料庫
- js去除重複字串JS字串
- Python中去除重複資料的方法有哪些?Python
- asp.net 之StringBuilder 去除重複資料ASP.NETUI
- UNIX下去除檔案中重複資料的方法(轉)
- List中去除重複物件物件
- python中列表如何去除重複Python
- 使用HashSet<>去除重複元素的集合
- JUnit5的條件測試、巢狀測試、重複測試巢狀
- PHP陣列去除空白或重複元素PHP陣列
- 陣列去除重複的幾個方法陣列
- 利用excel去除txt文字中重複項Excel
- JAVA 如何實現大文字去除重複行Java
- 如何去除 EXCEL 檔案中的重複行Excel
- 使用Oracle分析函式去除重複記錄Oracle函式
- mysql去除某些欄位重複的紀錄MySql
- 力扣-316. 去除重複字母力扣
- 如何去除有序陣列中的重複元素陣列
- 刪除重複資料
- mysql 清除重複資料MySql
- 正規表示式去除連續重複的字元字元
- php多維陣列去除重複值的方法PHP陣列
- [Leetcode]316.去除重複字母LeetCode
- 去除重複字母(不同字元的最小序列)問題字元
- 小測試:HashSet可以插入重複的元素嗎?
- MySQL資料庫行去重複和列去重複MySql資料庫
- dataset 判斷整列是否有重複,找出重複資料
- mysql查詢表裡的重複資料方法和刪除重複資料MySql
- 測試工作重複枯燥,必須成為測開才能避免?
- mongodb刪除重複資料MongoDB
- mysql避免插入重複資料MySql
- MySQL 處理重複資料MySql
- MySQL刪除重複資料MySql
- Oracle 重複資料處理Oracle
- C# datatable中重複資料去重C#