NTH_VALUE

Returns the value at the specified offset from beginning the window. Offsets start at 1. The offset can be any positive integer. If the offset is null or greater than the number of values in the window, null is returned.

ParameterTypeDescription
value
any
The name of the column to evaluate
offset
integer
the position of the value to use
Returns: any

Example

query:

SELECT account, create_date, order_value, NTH_VALUE(order_value,2) OVER (PARTITION BY account ORDER BY create_date range between unbounded preceding and unbounded following)
  FROM jun_2017_orders

result:

account create_date order_value nth_value
Condax 2017-06-01 564 4642
Condax 2017-06-03 4642 4642
Condax 2017-06-04 3908 4642
Condax 2017-06-04 49 4642
Condax 2017-06-05 54 4642
Condax 2017-06-05 5429 4642
Condax 2017-06-05 4988 4642
Condax 2017-06-05 5644 4642
Condax 2017-06-06 55 4642
Condax 2017-06-06 956 4642
Condax 2017-06-07 1103 4642
Condax 2017-06-09 48 4642
Condax 2017-06-12 5344 4642
Condax 2017-06-15 58 4642
Condax 2017-06-20 54 4642
Condax 2017-06-20 983 4642
Condax 2017-06-25 55 4642
Condax 2017-06-26 1135 4642
Conecom 2017-06-10 1056 1183
Conecom 2017-06-15 1183 1183
Conecom 2017-06-16 3844 1183
Conecom 2017-06-27 1115 1183