LEAD
Overview
The LEAD()
window function takes a column and an integer offset as arguments and returns the value of the cell in that column that is located at the specified number of rows after the current row. It can be used with all data types supported by Oxla
Syntax
The syntax for this function is as follows:
The output’s type for this function is the same as the input’s one. If there is no row and value that meets the offset criteria, it returns the specified default value, which must be of a type compatible with the input value.
Parameters
expression
: column, which will be referencedoffset
: numeric indicator of the row that is relative to the current one (optional, if not specified 1 will be returned)default
: value that wil be returned if theoffset
is out of range (optional, if not specifiedNULL
will be returned)
Examples
In this example, we will use the winsales
table that stores details about some sales transactions:
LEAD(expression, offset)
In this example, we will focus on executing the LEAD()
function with expression and offset parameters’ values specified:
The following query returns the buyer ID, date ID, quantity and previous quantity for all rows with buyer ID equal to c
:
Expression, Offset And Default Specified
In this example, we will focus on executing the LEAD()
function with expression, offset and default parameters’ values specified:
The above query returns the buyer ID, date ID, quantity and following buyer ID for all rows: