Yet another neat addition to the family of Analytics in 11g Release 2.
With this new function , I can look up the value of nth row .
The following gives the 4th salary from the dept 30 ( look at the column nv) .
1 SELECT empno,
2 ename,
3 deptno,
4 sal,
5 first_value(sal) over(PARTITION BY deptno ORDER BY empno) fv,
6 nth_value((sal), 4) over(PARTITION BY deptno ORDER BY empno) nv,
7 last_value(sal) over(PARTITION BY deptno ORDER BY empno
8 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) lv
9 FROM emp
10* WHERE deptno = 30
SQL> /
EMPNO ENAME DEPTNO SAL FV NV LV
---------- ---------- ---------- ---------- ---------- ---------- ----------
7499 ALLEN 30 1600 1600 950
7521 WARD 30 1250 1600 950
7654 MARTIN 30 1250 1600 950
7698 BLAKE 30 2850 1600 2850 950
7844 TURNER 30 1500 1600 2850 950
7900 JAMES 30 950 1600 2850 950
6 rows selected.
Good luck ...
With this new function , I can look up the value of nth row .
The following gives the 4th salary from the dept 30 ( look at the column nv) .
1 SELECT empno,
2 ename,
3 deptno,
4 sal,
5 first_value(sal) over(PARTITION BY deptno ORDER BY empno) fv,
6 nth_value((sal), 4) over(PARTITION BY deptno ORDER BY empno) nv,
7 last_value(sal) over(PARTITION BY deptno ORDER BY empno
8 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) lv
9 FROM emp
10* WHERE deptno = 30
SQL> /
EMPNO ENAME DEPTNO SAL FV NV LV
---------- ---------- ---------- ---------- ---------- ---------- ----------
7499 ALLEN 30 1600 1600 950
7521 WARD 30 1250 1600 950
7654 MARTIN 30 1250 1600 950
7698 BLAKE 30 2850 1600 2850 950
7844 TURNER 30 1500 1600 2850 950
7900 JAMES 30 950 1600 2850 950
6 rows selected.
Good luck ...