Updated on 2024-09-19 GMT+08:00

Extrema Function

Description

Extrema functions return the maximum or minimum value after evaluating zero or more specified fields. For details, see Table 1.

Pay attention to the following points when using the extrema functions:

  • If no field is set, null is returned. Fields must be able to be converted to common data types.
  • If all fields are null, null is returned. If only some fields are null, these fields will be ignored.
  • If a field contains both numbers and strings, the function compares them as strings.
  • If all columns are integers, the function compares them as long values.
  • If all fields are numbers and at least one is a float value, the function compares them as float values.

Syntax

SELECT GREATEST(fieldname1,fieldname2) AS the_greatest_field

Extrema Function Statements

Table 1 Extrema function statements

Statement

Description

Example

GREATEST([expr1, ...])

Returns the maximum value among zero or multiple fields.

SELECT GREATEST(fieldname1,fieldname2)

LEAST([expr1, ...])

Returns the minimum value among zero or multiple fields.

SELECT LEAST(fieldname1,fieldname2)