存储在 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)
推广内容