greatest
description
Syntax
greatest(col_a, col_b, …, col_n)
column supports the following types: TINYINT SMALLINT INT BIGINT LARGEINT FLOAT DOUBLE STRING DATETIME DECIMAL
Compares the size of n columns and returns the largest among them. If there is NULL in column, it returns NULL.
example
1. mysql> select greatest(-1, 0, 5, 8);
2. +-----------------------+
3. | greatest(-1, 0, 5, 8) |
4. +-----------------------+
5. | 8 |
6. +-----------------------+
7. mysql> select greatest(-1, 0, 5, NULL);
8. +--------------------------+
9. | greatest(-1, 0, 5, NULL) |
10. +--------------------------+
11. | NULL |
12. +--------------------------+
13. mysql> select greatest(6.3, 4.29, 7.6876);
14. +-----------------------------+
15. | greatest(6.3, 4.29, 7.6876) |
16. +-----------------------------+
17. | 7.6876 |
18. +-----------------------------+
19. mysql> select greatest("2022-02-26 20:02:11","2020-01-23 20:02:11","2020-06-22 20:02:11");
20. +-------------------------------------------------------------------------------+
21. | greatest('2022-02-26 20:02:11', '2020-01-23 20:02:11', '2020-06-22 20:02:11') |
22. +-------------------------------------------------------------------------------+
23. | 2022-02-26 20:02:11 |
24. +-------------------------------------------------------------------------------+
keywords
1. GREATEST
