Home » SQL & PL/SQL » SQL & PL/SQL » Re: fetching the current and previous column value for the current record
Re: fetching the current and previous column value for the current record [message #2554] Thu, 25 July 2002 10:10
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Analytical functions (using LAG):

sql>select empno, ename,
  2         lag(empno, 1, empno) over (order by empno) previous_empno
  3    from emp  
  4   order by empno;
 
    EMPNO ENAME      PREVIOUS_EMPNO
--------- ---------- --------------
     7369 SMITH                7369
     7499 ALLEN                7369
     7521 WARD                 7499
     7566 JONES                7521
     7654 MARTIN               7566
     7698 BLAKE                7654
     7782 CLARK                7698
     7788 SCOTT                7782
     7839 KING                 7788
     7844 TURNER               7839
     7876 ADAMS                7844
     7900 JAMES                7876
     7902 FORD                 7900
     7934 MILLER               7902
Previous Topic: SQL Statement
Next Topic: Optimize query
Goto Forum:
  


Current Time: Thu Apr 25 22:11:45 CDT 2024