罗罗 2019-04-03
代码如下:
select rownum,ename,job, row_number() over (order by rownum) row_number from emp; ROWNUM ENAME JOB ROW_NUMBER ---------- ---------- --------- ---------- 1 SMITH CLERK 1 2 ALLEN SALESMAN 2 3 WARD SALESMAN 3 4 JONES MANAGER 4 5 MARTIN SALESMAN 5 6 BLAKE MANAGER 6 7 CLARK MANAGER 7 8 SCOTT ANALYST 8 9 KING PRESIDENT 9 10 TURNER SALESMAN 10 11 ADAMS CLERK 11 12 JAMES CLERK 12 13 FORD ANALYST 13 14 MILLER CLERK 14
代码如下:
with row_number_test as( select 22 a,'twenty two' b from dual union all select 1,'one' from dual union all select 13,'thirteen' from dual union all select 5,'five' from dual union all select 4,'four' from dual) select a,b, row_number() over (order by b) from row_number_test order by a;
代码如下:
A B ROW_NUMBER()OVER(ORDERBYB) -- ---------- -------------------------- 1 one 3 4 four 2 5 five 1 13 thirteen 4 22 twenty two 5
代码如下:
with row_number_test as( select 22 a,'twenty two' b,'*' c from dual union all select 1,'one','+' from dual union all select 13,'thirteen','*' from dual union all select 5,'five','+' from dual union all select 4,'four','+' from dual) select a,b, row_number() over (partition by c order by b) row_number from row_number_test order by a;
代码如下:
A B ROW_NUMBER -- ---------- ---------- 1 one 3 4 four 2 5 five 1 13 thirteen 1 22 twenty two