- Kategorien:
GREATEST¶
Gibt den größten Wert aus einer Liste von Ausdrücken zurück. GREATEST unterstützt alle Datentypen, einschließlich VARIANT.
- Siehe auch:
Syntax¶
GREATEST( <expr1> [ , <expr2> ... ] )
Argumente¶
exprN
Die Argumente müssen mindestens einen Ausdruck enthalten. Alle Ausdrücke sollten vom gleichen Typ oder einem kompatiblen Typ sein.
Rückgabewerte¶
Das erste Argument bestimmt über den Rückgabetyp:
Wenn der erste Typ numerisch ist, wird der Rückgabetyp entsprechend den numerischen Typen in der Liste aller Argumente „verbreitert“.
Wenn der erste Typ nicht numerisch ist, müssen alle anderen Argumente in den ersten Typ konvertierbar sein.
Wenn eines der Argumente NULL ist, wird NULL zurückgegeben.
Sortierungsdetails¶
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.
Beispiele¶
Die folgenden Beispiele verwenden die Funktion GREATEST.
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 |
+-------+-------+----------+