借助以下示例,我们可以了解如何将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)
上面的查询显示了如何将INTERVAL关键字与EXTRACT()
MySQL表查询中使用的函数一起使用。
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()
用于特定给定日期的函数一起使用。