让我们首先创建一个表-
create table DemoTable1471 -> ( -> EmployeeJoiningDate date, -> EmployeeRelievingDate date -> );
使用插入命令在表中插入一些记录-
insert into DemoTable1471 values('2018-06-21','2018-12-21'); insert into DemoTable1471 values('2017-01-19','2019-01-31'); insert into DemoTable1471 values('2015-12-31','2016-03-01');
使用select语句显示表中的所有记录-
select * from DemoTable1471;
这将产生以下输出-
+---------------------+-----------------------+ | EmployeeJoiningDate | EmployeeRelievingDate | +---------------------+-----------------------+ | 2018-06-21 | 2018-12-21 | | 2017-01-19 | 2019-01-31 | | 2015-12-31 | 2016-03-01 | +---------------------+-----------------------+ 3 rows in set (0.00 sec)
这是计算两个日期之间的天的查询-
select datediff(EmployeeRelievingDate,EmployeeJoiningDate) as EmployeeWorkDays from DemoTable1471;
这将产生以下输出-
+------------------+ | EmployeeWorkDays | +------------------+ | 183 | | 742 | | 61 | +------------------+ 3 rows in set (0.00 sec)