nth()

Aggregate. Returns the nth value from a group of values. The first argument determines which value is returned.

Syntax

nth ( number, expression )

Parameters

number

An integer specifying which record in the group to reference. If no group order is specified, the default order is arrival, where 0 would be the most recent record. If group order is specified, then 0 will reference the first record in the group, 1 the next, etc...

expression

An expression that references the rows in the group. This will typically include references to one or more columns in the input. Supports any datatype.

Usage

The function returns the same datatype as its expression argument.

When assessing stock portfolios, use the nth function to identify a specific item in a list. For example, you can identify the day's third-highest traded stock price indicated by the third item in the index. The nth function's uses a 0-based index.

Note: If the number argument is greater than the number of elements in the group, this function returns a NULL value.