ORDERBY

Defines the expressions that determine the sort order within each of a window function’s partitions.

Syntax

ORDERBY ( [<orderBy_expression>[, <order>[, <orderBy_expression>[, <order>]] …]] )

Parameters

Term Definition
orderBy_expression (Optional) Any scalar expression that will be used used to sort the data within each of a window function’s partitions.
order (Optional) A two-part value of the form "<OrderDirection> [<BlankHandling>]".

<OrderDirection> specifies how to sort <orderBy_expression> values (i.e. ascending or descending). Valid values include:
DESC. Alternative value: 0(zero)/FALSE. Sorts in descending order of values of <orderBy_expression>.
ASC. Alternative value: 1/TRUE. Sorts in ascending order of values of <orderBy_expression>. This is the default value if <order> is omitted.

<BlankHandling> part is optional. It specifies how blanks are ordered. Valid values include:
BLANKS DEFAULT. This is the default value. The behavior for numerical values is blank values are ordered between zero and negative values. The behavior for strings is blank values are ordered before all strings, including empty strings.
BLANKS FIRST. Blanks are always ordered on the beginning, regardless of ascending or descending sorting order.
BLANKS LAST. Blanks are always ordered on the end, regardless of ascending or descending sorting order.

Return value

This function does not return a value.

Remarks

This function can only be used within a window function expression.

Example

See OFFSET.

Understanding ORDERBY, PARTITIONBY, and MATCHBY functions
INDEX
OFFSET
PARTITIONBY
MATCHBY
WINDOW
RANK
ROWNUMBER