NTH_VALUE
Takes the value from the Nth row of the window: the second, the third…
Syntax
NTH_VALUE(<expression>, <n>) OVER (
ORDER BY <sort key>
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
)
NTH_VALUE(<expression>, <n>) OVER (
PARTITION BY <group> ORDER BY <sort key>
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
)
Like FIRST_VALUE, but for any number: NTH_VALUE(salary, 2) is the second salary in the window. The number of rows stays the same, and each gets the value from its own window. If the window doesn't have an Nth row yet, the result is NULL.