먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable1471 -> ( -> EmployeeJoiningDate date, -> EmployeeRelievingDate date -> ); Query OK, 0 rows affected (0.57 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable1471 values('2018-06-21','2018-12-21'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1471 values('2017-01-19','2019-01-31'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1471 values('2015-12-31','2016-03-01'); Query OK, 1 row affected (0.11 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> 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)
다음은 두 날짜 사이의 날짜를 계산하는 쿼리입니다. -
mysql> select datediff(EmployeeRelievingDate,EmployeeJoiningDate) as EmployeeWorkDays from DemoTable1471;
이것은 다음과 같은 출력을 생성합니다 -
+------------------+ | EmployeeWorkDays | +------------------+ | 183 | | 742 | | 61 | +------------------+ 3 rows in set (0.00 sec)