/ Published in: SQL
A few examples of the LAG function.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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;
URL: http://www.databasestar.com/oracle-lag/