- 类别:
GREATEST¶
返回表达式列表中的最大值。如果任何实参值为 NULL,则结果为 NULL。GREATEST 支持所有数据类型,包括 VARIANT。
语法¶
GREATEST( <expr1> [ , <expr2> ... ] )
实参¶
exprN
实参必须包含至少一个表达式。所有表达式都应为相同类型或兼容的类型。
返回¶
第一个实参确定返回类型:
如果第一种类型是数值,则返回类型将根据所有实参列表中的数值类型“扩宽”。
如果第一种类型不是数值,则所有其他实参必须可转换为第一种类型。
排序规则详细信息¶
The collation specifications of all input arguments must be compatible.
The comparisons follow the collation based on the input arguments' collations and precedences.
The collation of the result of the function is the highest-precedence collation of the inputs.
示例¶
基本示例:
CREATE TABLE test_table_1_greatest (col_1 INTEGER, col_2 INTEGER, col_3 INTEGER, col_4 FLOAT); INSERT INTO test_table_1_greatest (col_1, col_2, col_3, col_4) VALUES (1, 2, 3, 4.00), (2, 4, -1, -2.00), (3, 6, NULL, 13.45);SELECT col_1, col_2, col_3, GREATEST(col_1, col_2, col_3) AS greatest FROM test_table_1_greatest ORDER BY col_1;+-------+-------+-------+----------+ | COL_1 | COL_2 | COL_3 | GREATEST | |-------+-------+-------+----------| | 1 | 2 | 3 | 3 | | 2 | 4 | -1 | 4 | | 3 | 6 | NULL | NULL | +-------+-------+-------+----------+SELECT col_1, col_4, GREATEST(col_1, col_4) AS greatest FROM test_table_1_greatest ORDER BY col_1;+-------+-------+----------+ | COL_1 | COL_4 | GREATEST | |-------+-------+----------| | 1 | 4 | 4 | | 2 | -2 | 2 | | 3 | 13.45 | 13.45 | +-------+-------+----------+