Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
LEAD and LAG
12. Function LAG(x, y, z)
FIRST_VALUE, LAST_VALUE, NTH_VALUE
Summary

Instruction

The last version of LAG takes three arguments and is very analogous to LEAD with three arguments:

SELECT
  name,
  opened,
  LAG(opened,2,'2000-01-01') OVER(ORDER BY opened)
FROM website;

The last argument is the value displayed when no 'lag' (previous) row can be found. Remember that this value must be of the type corresponding to the column.

Exercise

Modify the template from the previous exercise so that it shows -1.00 for rows with no revenue value 3 days before.

Stuck? Here's a hint!

Use LAG with three arguments.