mysql数据库求字段的最大值和最小值
概述
MySQL的
GREATEST
函数求最大值。MySQL的
LEAST
函数求最小值。
示例:
sql
mysql> SELECT GREATEST(DATE('2016-05-02'), DATE('2015-05-02'), DATE('2017-05-02'));
+----------------------------------------------------------------------+
| GREATEST(DATE('2016-05-02'), DATE('2015-05-02'), DATE('2017-05-02')) |
+----------------------------------------------------------------------+
| 2017-05-02 |
+----------------------------------------------------------------------+
1 row in set (0.03 sec)
mysql> SELECT LEAST(DATE('2016-05-02'), DATE('2015-05-02'), DATE('2017-05-02'));
+-------------------------------------------------------------------+
| LEAST(DATE('2016-05-02'), DATE('2015-05-02'), DATE('2017-05-02')) |
+-------------------------------------------------------------------+
| 2015-05-02 |
+-------------------------------------------------------------------+
1 row in set (0.00 sec)