EMPNO DEPTNO SAL RANK
---------- ---------- ---------- ----------
7839 10 5000 1
7902 20 3000 2
7788 20 3000 2
7566 20 2975 3
7698 30 2850 4
7782 10 2450 5
7499 30 1600 6
7844 30 1500 7
7934 10 1300 8
7521 30 1250 9
7654 30 1250 9
7876 20 1100 10
7900 30 950 11
7369 20 800 12
14 rows selected.
SQL> select empno,deptno,sal ,dense_rank() over (partition by deptno order by sal desc) rank from emp;
EMPNO DEPTNO SAL RANK
---------- ---------- ---------- ----------
7839 10 5000 1
7782 10 2450 2
7934 10 1300 3
7788 20 3000 1
7902 20 3000 1
7566 20 2975 2 --不跳跃
7876 20 1100 3
7369 20 800 4
7698 30 2850 1
7499 30 1600 2
7844 30 1500 3
7654 30 1250 4
7521 30 1250 4
7900 30 950 5
14 rows selected.
使用ROW_NUMBER删除重复数据
---假设表TAB中有a,b,c三列,可以使用下列语句删除a,b,c都相同的重复行。
DELETE FROM (select year,QUARTER,RESULTS,row_number() over(partition by YEAR,QUARTER,RESULTS order by YEAR,QUARTER,RESULTS) AS ROW_NO FROM SALE )
WHERE ROW_NO>1