儲存在 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)

更新於:2020-01-28

132 次瀏覽

開啟你的職業生涯

透過完成課程來獲取認證

開始
廣告
© . All rights reserved.