Updated on 2023-10-25 GMT+08:00

ordinal

This function is used to sort input variables in ascending order and return the value at the position specified by nth.

Syntax

ordinal(bigint <nth>, <var1>, <var2>[,...])

Parameters

Table 1 Parameters

Parameter

Mandatory

Type

Description

nth

Yes

BIGINT

Position value to be returned

var

Yes

BIGINT, DOUBLE, DATETIME, or STRING

Value to be sorted

Return Values

The return value is of the DOUBLE or DECIMAL type.

  • Value of the nth bit. If there are no implicit conversions, the return value has the same data type as the input parameter.
  • If there are type conversions, DOUBLE is returned for the conversion between DOUBLE, BIGINT, and STRING, and DATETIME is returned for the conversion between STRING and DATETIME. Other implicit conversions are not allowed.
  • NULL indicates the minimum value.

Example Code

The value 2 is returned.

select ordinal(3, 1, 3, 2, 5, 2, 4, 9);