Oracle 數據庫數據排名函數: rank() 和dense_rank() 。數據庫
--------------------------------------------間斷排名(也稱強制排名) rank() --------------------------------------------函數
SQL: SELECT empno,ename,sal,rank() over(ORDER BY nvl(sal,0) DESC) x FROM emp;spa
EMPNOci |
ENAMEtable |
SAL數據 |
Xtab |
7369di |
SMITHco |
8000ab |
1 |
7839 |
KING |
8000 |
1 |
7782 |
CLARK |
7450 |
3 |
7788 |
SCOTT |
7000 |
4 |
7698 |
BLAKE |
6850 |
5 |
7902 |
FORD |
6000 |
6 |
7566 |
JONES |
5975 |
7 |
7499 |
ALLEN |
5600 |
8 |
7844 |
TURNER |
5500 |
9 |
7521 |
WARD |
5250 |
10 |
7654 |
MARTIN |
5250 |
10 |
7876 |
ADAMS |
4100 |
12 |
9000 |
xiaoming |
|
13
|
--------------------------------------------不間斷排名 dense_rank() -----------------------------------------------
SQL: SELECT empno,ename,sal,dense_rank() over(ORDER BY nvl(sal,0) DESC) x FROM emp;
EMPNO |
ENAME |
SAL |
X |
7369 |
SMITH |
8000 |
1 |
7839 |
KING |
8000 |
1 |
7782 |
CLARK |
7450 |
2 |
7788 |
SCOTT |
7000 |
3 |
7698 |
BLAKE |
6850 |
4 |
7902 |
FORD |
6000 |
5 |
7566 |
JONES |
5975 |
6 |
7499 |
ALLEN |
5600 |
7 |
7844 |
TURNER |
5500 |
8 |
7521 |
WARD |
5250 |
9 |
7654 |
MARTIN |
5250 |
9 |
7876 |
ADAMS |
4100 |
10 |
9000 |
xiaoming |
|
11 |