儲存在 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)
推廣內容
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP