Skip to main content

Last Value

Definition

The lastValue method allows you to add the LAST_VALUE function to the query. The LAST_VALUE function returns the last value in an ordered partition of a result set.

Available methods

  • lastValue(KColumn kColumn): Receives a KColumn or a KTableColumn which will be supplied to the LAST_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,
lastValue(APP_USER.FIRST_NAME).over(
wd()
.partitionBy(APP_USER.ROLE_ID)
.orderBy(APP_USER.FIRST_NAME)
)
)
.from(APP_USER)
.multiple();

SQL generated:

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

Parameters:

  • None