- Catégories :
GREATEST¶
Renvoie la plus grande valeur d’une liste d’expressions. GREATEST prend en charge tous les types de données, y compris VARIANT.
- Voir aussi :
Syntaxe¶
GREATEST( <expr1> [ , <expr2> ... ] )
Arguments¶
exprN
Les arguments doivent inclure au moins une expression. Toutes les expressions doivent être du même type ou de types compatibles.
Renvoie¶
Le premier argument détermine le type de renvoi :
Si le premier type est numérique, le type de renvoi sera « élargi » en fonction des types numériques de la liste de tous les arguments.
Si le premier type n’est pas numérique, tous les autres arguments doivent être convertibles en premier type.
Si un argument est NULL, renvoie NULL.
Détails du classement¶
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.
Exemples¶
Les exemples suivants utilisent la fonction 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 |
+-------+-------+----------+