MySQL 如何在提取日期部分时使用MySQL的INTERVAL关键字?
通过以下示例,我们可以了解如何在MySQL表查询中使用INTERVAL关键字与EXTRACT()函数一起使用:
mysql> Select StudentName, RegDate, EXTRACT(YEAR from RegDate+INTERVAL 2 year) AS 'Two Year Interval' from testing where StudentName = 'Gaurav';
+-------------+---------------------+-------------------+
| StudentName | RegDate | Two Year Interval |
+-------------+---------------------+-------------------+
| Gaurav | 2017-10-29 08:48:33 | 2019 |
+-------------+---------------------+-------------------+
1 row in set (0.02 sec)
上述查询显示了如何在MySQL表查询中使用INTERVAL关键字与EXTRACT()函数。
mysql> Select EXTRACT(Year from '2017-10-22 05:03:45' + INTERVAL 2 Year) AS 'Two Year Interval';
+-------------------+
| Two Year Interval |
+-------------------+
| 2019 |
+-------------------+
1 row in set (0.00 sec)
上述查询显示了如何在特定给定日期的情况下使用INTERVAL关键字与EXTRACT()函数。
阅读更多:MySQL 教程