NTH_VALUE
Purpose
The NTH_VALUE function returns the value of expr of the nth row in the window specified by the over_clause.
Syntax
nth_value::=
Usage Notes
NTH_VALUEis only available as an analytic function (i.e., in combination with anover_clause). For more information, refer to Analytic Functions section.- The default value of the
FROMconfiguration isFROM FIRST. - The default value of the null treatment is
RESPECT NULLS. - The value of
nhas to beNULLor aDECIMALvalue greater than0.- If the value of
nisNULL, the result of the function isNULL. - If the value of
nis less than or equal to0, Exasol returns an error. - If the value of
nis greater than the number of rows in the window, the result ofNTH_VALUEisNULL.
- If the value of
Example
Analytic Function
SELECT
id, department, hire_date,
NTH_VALUE(id, 3) FROM LAST RESPECT NULLS
OVER (PARTITION BY department ORDER BY hire_date) NTH_VAL
FROM employee_table ORDER BY department, hire_date;
Result
| ID | DEPARTMENT | HIRE_DATE | NTH_VAL |
| 2005 | ACCOUNTS | 2013-01-01 | NULL |
| 2003 | ACCOUNTS | 2015-07-01 | NULL |
| 2002 | ACCOUNTS | 2017-01-01 | 2003 |
| 2004 | ACCOUNTS | 2017-01-01 | 2003 |
| 2001 | ACCOUNTS | 2018-07-01 | 2002 |
| 1003 | HR | 2014-01-01 | NULL |
| 1002 | HR | 2016-01-01 | 1003 |
| 1004 | HR | 2016-01-01 | 1003 |
| 1001 | HR | 2018-01-01 | 1002 |