我們可以將算術運算符(+、-、*、/)與 INTERVAL 關鍵字的單位值一起使用,如下 –
使用加法 (+)
mysql> Select date('2017-10-22' + INTERVAL 2+2 Year) AS 'Date After (2+2)Years'; +------------------------+ | Date After (2+2) Years | +------------------------+ | 2021-10-22 | +------------------------+ 1 row in set (0.00 sec)
登錄后復制
使用減法 (-)
mysql> Select date('2017-10-22' + INTERVAL 2-2 Year) AS 'Date After (2-2)Years'; +------------------------+ | Date After (2-2) Years | +------------------------+ | 2017-10-22 | +------------------------+ 1 row in set (0.00 sec)
登錄后復制
乘法的使用 (*)
mysql> Select date('2017-10-22' + INTERVAL 2*2 Year) AS 'Date After (2*2)Years'; +------------------------+ | Date After (2*2) Years | +------------------------+ | 2021-10-22 | +------------------------+ 1 row in set (0.00 sec)
登錄后復制
使用除號 (/)
mysql> Select date('2017-10-22' + INTERVAL 2/2 Year) AS 'Date After (2/2) Years'; +------------------------+ | Date After (2/2) Years | +------------------------+ | 2018-10-22 | +------------------------+ 1 row in set (0.00 sec)
登錄后復制
以上就是如何在 MySQL 中將算術運算符(+、-、*、/)與 INTERVAL 關鍵字的單位值一起使用?的詳細內容,更多請關注www.92cms.cn其它相關文章!