Overview
TheLEAD()
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: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 thewinsales
table that stores details about some sales transactions:
LEAD(expression, offset)
In this example, we will focus on executing theLEAD()
function with expression and offset parameters’ values specified:
c
:
Expression, Offset And Default Specified
In this example, we will focus on executing theLEAD()
function with expression, offset and default parameters’ values specified:
Time Series: LEAD() to Compare Next Day’s Sales Quantity
In this example, we will use LEAD() to compare each day’s sales quantity (qty
) with the next day’s quantity, ordered by dateid
: