DB2刪除重復(fù)數(shù)據(jù)的實(shí)現(xiàn)
DB2刪除重復(fù)數(shù)據(jù)使我們經(jīng)常使用的操作,下面就教您DB2刪除重復(fù)數(shù)據(jù)的方法,希望可以對(duì)您學(xué)習(xí)DB2刪除重復(fù)數(shù)據(jù)方面有所幫助。
使用ROW_NUMBER 刪除重復(fù)數(shù)據(jù)
假設(shè)表TAB中有a,b,c三列,可以使用下列語(yǔ)句刪除a,b,c都相同的重復(fù)行。
以下是代碼片段:
- delete from (select * from (select a,b,c,row_number() over(partition by a,b,c order by a,b,c) as row_num from tab) as e where row_num >1)
如果數(shù)據(jù)量太大可以采用如下方法:
以下是代碼片段:
- Create table emp_profile_temp like emp_profile;
大數(shù)據(jù)量采用 LOAD FROM CURSUR
以下是代碼片段:
- DECLARE mycursor CURSOR FOR SELECT distinct * FROM emp_profile; LOAD FROM mycursor OF CURSOR INSERT INTO emp_profile_temp;
以下是代碼片段:
- drop table emp_profile; rename table emp_profile_temp to emp_profile