當我們嘗試對表中存儲的日期值進行此類操作時,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)
登錄后復制
以上就是加法、減法、乘法和除法運算符如何處理 MySQL 表中存儲的日期值?的詳細內容,更多請關注www.92cms.cn其它相關文章!