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_IdStart_DatePrev_Start_Date
150020/02/2008NULL
150022/02/200820/02/2008
150023/02/200822/02/2008