PL/SQL Lag
Oracle PL/SQL Lag Function
The Lag function returns values from a previous row in the table.
The Lag Function syntax:
lag ( exp [, offset [, default] ] )
over ( [ query_partition_clause ] order_by_clause )
Example:
Select job_id, start_date, lag (start_date,1) over (ORDER BY start_date) AS prev_start_date From employee Where job_id = 1500;
Job_Id | Start_Date | Prev_Start_Date |
1500 | 20/02/2008 | NULL |
1500 | 22/02/2008 | 20/02/2008 |
1500 | 23/02/2008 | 22/02/2008 |