Sorts the values of the input variables in ascending order and returns the value that is ranked nth.
Syntax
ordinal(bigint <nth>, <var1>, <var2>[,...])
Parameters
nth: required. The position of the value, which starts from 1. A value of the BIGINT type. This parameter specifies the position of the value that you want to return. If the value is null, null is returned.
var: required. The values that you want to sort. A value of the BIGINT, DOUBLE, DATETIME, or STRING type.
Return value
The value that is ranked nth is returned. If no implicit conversion is performed, the return value is of the same data type as the input parameter.
If a data type conversion is performed among the DOUBLE, BIGINT, and STRING types, a value of the DOUBLE type is returned. If a data type conversion is performed between the STRING and DATETIME types, a value of the DATETIME type is returned. Implicit conversions of other data types are not allowed.
The value null is interpreted as the minimum value.
Examples
-- The return value is 3.
SELECT ordinal(3, 1, 3, 7, 5, 2, 4, 6);
Related functions
For more information, see Other functions.