Return to Snippet

Revision: 71352
at February 21, 2017 13:19 by bbrumm


Initial Code
SELECT * FROM student;

--Example 1
SELECT student_id, first_name, last_name, fees_required,
LAG(fees_required) OVER (ORDER BY fees_required ASC) AS prev_fees_required
FROM student
ORDER BY student_id ASC;

--Example 2
SELECT student_id, first_name, last_name, fees_required,
LAG(fees_required) OVER (ORDER BY fees_required ASC) AS prev_fees_required
FROM student
ORDER BY fees_required ASC;

--Example 3
SELECT student_id, first_name, last_name, fees_required,
LAG(fees_required, 3, 0) OVER (ORDER BY fees_required ASC) AS prev_fees_required
FROM student
ORDER BY fees_required ASC;

Initial URL
http://www.databasestar.com/oracle-lag/

Initial Description
A few examples of the LAG function.

Initial Title
Oracle LAG Function

Initial Tags
sql, Oracle

Initial Language
SQL