让我们首先创建一个表-
create table DemoTable -> ( -> JoiningDate datetime -> );
使用插入命令在表中插入一些记录-
insert into DemoTable values('2015-01-21'); insert into DemoTable values('2017-04-02'); insert into DemoTable values('2018-12-31');
使用select语句显示表中的所有记录-
select *from DemoTable;
这将产生以下输出-
+---------------------+ | JoiningDate | +---------------------+ | 2015-01-21 00:00:00 | | 2017-04-02 00:00:00 | | 2018-12-31 00:00:00 | +---------------------+ 3 rows in set (0.00 sec)
这是实现DATE_ADD()并添加一年的查询-
select date_add(JoiningDate, interval 1 year) from DemoTable;
这将产生以下输出-
+----------------------------------------+ | date_add(JoiningDate, interval 1 year) | +----------------------------------------+ | 2016-01-21 00:00:00 | | 2018-04-02 00:00:00 | | 2019-12-31 00:00:00 | +----------------------------------------+ 3 rows in set (0.00 sec)