在实际工作中,如果一张表中有重复的行,将会影响查询和统计结果的正确性.现在以scott用户为例,使用row_number() 函数来解决这个问题.
首先创建名为"e"的表.
SCOTT> create table e as select * from emp;
SCOTT> select * from e;
现在向"e"表中插入重复数据,
SCOTT> insert into e as select * from emp where deptno=20;
使用子查询语句来找出重复的语句,
SCOTT> select ename,no from (select ename,row_number() over (partition by empno order by empno)no from e) where no>1;
转载于:https://blog.51cto.com/amadou/937723