ROWNUM和之间有什么区别ROW_NUMBER ?
ROWNUM
ROW_NUMBER
ROWNUM是一个“伪列”,它为查询返回的每一行分配一个数字:
SQL> select rownum, ename, deptno 2 from emp; ROWNUM ENAME DEPTNO ---------- ---------- ---------- 1 SMITH 99 2 ALLEN 30 3 WARD 30 4 JONES 20 5 MARTIN 30 6 BLAKE 30 7 CLARK 10 8 SCOTT 20 9 KING 10 10 TURNER 30 11 FORD 20 12 MILLER 10
ROW_NUMBER是一种分析函数,根据行在一组行中的顺序为每行分配一个数字:
SQL> select ename, deptno, row_number() over (partition by deptno order by ename) rn 2 from emp; ENAME DEPTNO RN ---------- ---------- ---------- CLARK 10 1 KING 10 2 MILLER 10 3 FORD 20 1 JONES 20 2 SCOTT 20 3 ALLEN 30 1 BLAKE 30 2 MARTIN 30 3 TURNER 30 4 WARD 30 5 SMITH 99 1