Description: LAG provides access to more than one row of a table at the same time without a self-join. Given a series of rows returned from a query and a position of the cursor, LAG provides access to a row at a given physical offset prior to that position.

LAG(<value expression>, <offset>, <default>)
OVER ([<query PARTITION clause>] <order_by_clause>)
conn oe/oe
SELECT last_name, hire_date, salary,
LAG(salary, 1, 0) OVER (ORDER BY hire_date) AS PREV_SAL
FROM employees
WHERE job_id = 'PU_CLERK';

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.