All Products
Search
Document Center

MaxCompute:LEAST

Last Updated:Oct 23, 2025

LEAST compares a group of values and returns the minimum value.

Syntax

least(<var1>, <var2>[,...])

Parameters

var: required. The input value. The value can be of the BIGINT, DOUBLE, DECIMAL, DATETIME, DATE, or STRING type.

Return value

  1. Returns the minimum value of the input parameters.

  • When the data types of input parameters are the same, the return value is of the same data type as the input parameters.

  • When the data types of input parameters are different, implicit conversions are performed based on the following rules:

    • Comparisons among DOUBLE, BIGINT, and STRING types are converted to the DOUBLE type.

    • Comparisons among DECIMAL, DOUBLE, BIGINT, and STRING types are converted to the DECIMAL type.

    • Comparisons between STRING and DATETIME types are converted to the DATETIME type.

      Note

      When the input format is a STRING type in the format of yyyy-mm-dd hh:mi:ss, and the data type version of the MaxCompute project is 1.0, the input is implicitly converted to the DATETIME type before computation. For data type version settings, see Data type version 1.0.

  1. NULL values are treated as the minimum value by default. When all input parameters are NULL, the result is NULL.

Example

-- Returns 2.
SELECT least(5, 2, 7);
-- Returns 1.1111.
SELECT least(3,2.5,'1.1111');
-- Returns 12345678901234567890.123456789012345679.
SELECT least(12345678901234567890.12345678901234567890,12345678901234567890.523456789012345679BD);
-- Returns 2025-07-01 12:00:00.
set odps.sql.type.system.odps2=false;
SELECT LEAST(datetime'2025-07-01 12:00:00', '2025-07-02 12:00:00') AS result;
-- Returns 2025-02-02.
SELECT LEAST(date'2025-10-01', date'2025-10-03',date'2026-01-01',date'2025-02-02') AS result;

Related functions

LEAST function belongs to mathematical functions. For more information, see Mathematical functions.