Excellent!! That's all we wanted to teach you today. Let's review what we've learned:
LAG(x) give you the next/previous value in the column x, respectively.
LAG(x,y) give you the value in the column x of the row which is y rows after/before the current row, respectively.
LAST_VALUE(x) give you the first and last value in the column x, respectively.
NTH_VALUE(x,n) gives you the value in the column x of the n-th row.
NTH_VALUE usually require the window frame to be set to
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING.
Now, are you ready for a short quiz?