排序函数-分区范围-Oracle分析函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了排序函数-分区范围-Oracle分析函数相关的知识,希望对你有一定的参考价值。

ROW_NUMBER() -
Partition (group by) the expression values and assigns integer values to the rows depending on their order.

thx to Shouvik Basu < http://www.orafaq.com/node/55 >
  1. -- Example 1
  2. ROW_NUMBER () OVER (PARTITION BY A.LN ORDER BY A.FC_SET_UP_DT DESC)
  3. AS MAX_SEQ_NO
  4.  
  5.  
  6.  
  7. -- Example 2
  8.  
  9. /*
  10. ROW_NUMBER( ) gives a running serial number to a partition of records.
  11. It is very useful in reporting, especially in places where different partitions have their own serial numbers.
  12. In Query-5, the function ROW_NUMBER( ) is used to give separate sets of running serial to employees of departments 10 and 20 based on their HIREDATE.
  13. */
  14.  
  15. SELECT empno, deptno, hiredate,
  16. ROW_NUMBER( ) OVER (PARTITION BY
  17. deptno ORDER BY hiredate
  18. NULLS LAST) SRLNO
  19. FROM emp
  20. WHERE deptno IN (10, 20)
  21. ORDER BY deptno, SRLNO;
  22.  
  23. EMPNO DEPTNO HIREDATE SRLNO
  24. ------ ------- --------- ----------
  25. 7782 10 09-JUN-81 1
  26. 7839 10 17-NOV-81 2
  27. 7934 10 23-JAN-82 3
  28. 7369 20 17-DEC-80 1
  29. 7566 20 02-APR-81 2
  30. 7902 20 03-DEC-81 3
  31. 7788 20 09-DEC-82 4
  32. 7876 20 12-JAN-83 5
  33.  
  34. 8 ROWS selected.

以上是关于排序函数-分区范围-Oracle分析函数的主要内容,如果未能解决你的问题,请参考以下文章

lag与lead函数 oracle_11g

oracle菜鸟学习之 分析函数-排序

oracle 求和函数

最大日期间隔的分析函数范围窗口

Oracle分析函数之排序 row_number() & rank()

Oracle分析函数