此类计算可能会导致不可预测的结果,因为当日期表示为 MySQL 字符串时,MySQL 会尝试仅采用第一个出现的字符串来对字符串执行数字运算。以下示例将阐明它 -
mysql> select '2017-10-17' + 20;
+-------------------+
| '2017-10-17' + 20 |
+-------------------+
| 2037 |
+-------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select '2017-10-25' - 17;
+-------------------+
| '2017-10-25' - 17 |
+-------------------+
| 2000 |
+-------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select '2017-10-17' * 2;
+-------------------+
| '2017-10-17' * 20 |
+-------------------+
| 4034 |
+-------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select '2017-05-25'/5;
+----------------+
| '2017-05-25'/5 |
+----------------+
| 403.4 |
+----------------+
1 row in set, 1 warning (0.00 sec)
登录后复制
以上就是加法、减法、乘法和除法运算符如何处理表示为 MySQL 字符串的日期?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!