The LEAST function compares a group of values and returns the minimum value.
Command format
least(<var1>, <var2>[,...])Parameters
var: Required. An input value of the BIGINT, DOUBLE, DECIMAL, DATETIME, DATE, or STRING data type.
Return value
Returns the minimum value among the input parameters.
If the input parameters have the same data type, the return value has the same data type.
If the input parameters have different data types, the data types are implicitly converted based on the following rules:
If you compare values of the DOUBLE, BIGINT, and STRING types, they are converted to the DOUBLE type.
If you compare values of the DECIMAL, DOUBLE, BIGINT, and STRING types, they are converted to the DECIMAL type.
If you compare values of the STRING and DATETIME types, they are converted to the DATETIME type.
NoteIf a STRING value is in the
yyyy-mm-dd hh:mi:ssformat and the data type edition for your MaxCompute project is set to 1.0, the value is implicitly converted to the DATETIME type. For more information about how to set the data type edition, see Data type edition 1.0.
NULL is considered the minimum value. If all input parameters are NULL, the function returns NULL.
Examples
-- 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.
set odps.sql.type.system.odps2=true;
SELECT LEAST(date'2025-10-01', date'2025-10-03', date'2026-01-01',date'2025-02-02') AS result;Related functions
LEAST is a mathematical function. For more information about functions for data computing and data conversion, see Mathematical functions.