Posted By

bbrumm on 02/21/17


Tagged

sql Oracle


Versions (?)

Oracle LAG Function


 / Published in: SQL
 

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

A few examples of the LAG function.

  1. SELECT * FROM student;
  2.  
  3. --Example 1
  4. SELECT student_id, first_name, last_name, fees_required,
  5. LAG(fees_required) OVER (ORDER BY fees_required ASC) AS prev_fees_required
  6. FROM student
  7. ORDER BY student_id ASC;
  8.  
  9. --Example 2
  10. SELECT student_id, first_name, last_name, fees_required,
  11. LAG(fees_required) OVER (ORDER BY fees_required ASC) AS prev_fees_required
  12. FROM student
  13. ORDER BY fees_required ASC;
  14.  
  15. --Example 3
  16. SELECT student_id, first_name, last_name, fees_required,
  17. LAG(fees_required, 3, 0) OVER (ORDER BY fees_required ASC) AS prev_fees_required
  18. FROM student
  19. ORDER BY fees_required ASC;

Report this snippet  

You need to login to post a comment.