Skip to main content

Nth Value

Definition

The nthValue method allows you to add the NTH_VALUE function to the query. The NTH_VALUE function returns a value from the nth row in an ordered partition of a result set.

Available methods

  • nthValue(KColumn kColumn, int offset): Receives a KColumn or a KTableColumn and an offset which will be supplied to the NTH_VALUE function. .

To use this way, you need to import the static functions as follows:

import static com.myzlab.k.KFunction.*;

Example

Java code:

k
.select(
APP_USER.FIRST_NAME,
nthValue(APP_USER.FIRST_NAME, 3).over(
wd()
.partitionBy(APP_USER.ROLE_ID)
.orderBy(APP_USER.FIRST_NAME)
)
)
.from(APP_USER)
.multiple();

SQL generated:

SELECT
au.first_name,
NTH_VALUE(au.first_name, 3) OVER(
PARTITION BY au.role_id
ORDER BY au.first_name
)
FROM app_user au

Parameters:

  • None