Lead
Definition
The lead method allows you to add the LEAD function to the query. The LEAD function provides access to a row that follows the current row at a specified physical offset. It means that from the current row, the LEAD function can access data of the next row, the row after the next row, and so on.
Available methods
lead(KColumn kColumn): Receives aKColumnor aKTableColumnwhich will be supplied to theLEADfunction.lead(KColumn kColumn, int offset): Receives aKColumnor aKTableColumnand an offset which will be supplied to theLEADfunction.lead(KColumn kColumn, int offset, KBaseColumnCastable defaultValue): Receives aKColumnor aKTableColumnand an offset which will be supplied to theLEADfunction. Additionally, receives a default value which too will be supplied to theLEADfunction. Among the possible values of this default value are:KTableColumn,KColumn,Values.
To use this way, you need to import the static functions as follows:
import static com.myzlab.k.KFunction.*;
Example: lead(KColumn)
Java code:
k
.select(
APP_USER.FIRST_NAME,
lead(APP_USER.FIRST_NAME).over(wd())
)
.from(APP_USER)
.multiple();
SQL generated:
SELECT
au.first_name,
LEAD(au.first_name) OVER()
FROM app_user au
Parameters:
- None
Example: lead(KColumn, int)
Java code:
k
.select(
APP_USER.FIRST_NAME,
lead(APP_USER.FIRST_NAME, 2).over(wd())
)
.from(APP_USER)
.multiple();
SQL generated:
SELECT
au.first_name,
LEAD(au.first_name, 2) OVER()
FROM app_user au
Parameters:
- None
Example: lead(KColumn, int, KBaseColumnCastable)
Java code:
k
.select(
APP_USER.FIRST_NAME,
lead(APP_USER.FIRST_NAME, 2, val("No name")).over(wd())
)
.from(APP_USER)
.multiple();
SQL generated:
SELECT
au.first_name,
LEAD(au.first_name, 2, ?1) OVER()
FROM app_user au
Parameters:
- ?1: "No name"