加法、减法、乘法和除法运算符如何处理存储在 MySQL 表中的日期值?
当我们尝试对存储在表中的日期值进行此类操作时,MySQL会将日期值假定为数字并执行算术运算。
假设我们有一个名为“example”的表,在“orderdate”列中有一个日期值,那么以下算术运算将阐明上述内容-
mysql> select * from example; +------------+ | orderdate | +------------+ | 2017-05-25 | +------------+ 1 row in set (0.00 sec) mysql> select orderdate+10 from example; +--------------+ | orderdate+10 | +--------------+ | 20170535 | +--------------+ 1 row in set (0.00 sec) mysql> select orderdate*10 from example; +--------------+ | orderdate*10 | +--------------+ | 201705250 | +--------------+ 1 row in set (0.00 sec) mysql> select orderdate-10 from example; +--------------+ | orderdate-10 | +--------------+ | 20170515 | +--------------+ 1 row in set (0.00 sec) mysql> select orderdate/10 from example; +--------------+ | orderdate/10 | +--------------+ | 2017052.5 | +--------------+ 1 row in set (0.00 sec)