가장 빠르고 쉬운 방법은 MySQL BETWEEN 키워드를 사용하는 것입니다. 먼저 −
를 생성해 보겠습니다.mysql> create table DemoTable1413 -> ( -> EmployeeName varchar(20), -> EmployeeJoiningDate datetime -> ); Query OK, 0 rows affected (0.45 sec)
insert −
를 사용하여 테이블에 일부 레코드 삽입mysql> insert into DemoTable1413 values('Chris','2018-09-28 11 :10 :50'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1413 values('David','2019-09-28 11:10:50'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1413 values('Mike','2019-09-29 12:40:00'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1413 values('Carol','2019-09-28 12:06:10'); Query OK, 1 row affected (0.08 sec)
select −
를 사용하여 테이블의 모든 레코드 표시mysql> select * from DemoTable1413;
이것은 다음과 같은 출력을 생성합니다 -
+--------------+---------------------+ | EmployeeName | EmployeeJoiningDate | +--------------+---------------------+ | Chris | 2018-09-28 11:10:50 | | David | 2019-09-28 11:10:50 | | Mike | 2019-09-29 12:40:00 | | Carol | 2019-09-28 12:06:10 | +--------------+---------------------+ 4 rows in set (0.00 sec)
다음은 날짜 사이의 날짜 레코드를 검색하는 쿼리입니다 -
mysql> select * from DemoTable1413 -> where EmployeeJoiningDate between '2019-09-28' and '2019-09-28 23:59:59' -> limit 1;
이것은 다음과 같은 출력을 생성합니다 -
+--------------+---------------------+ | EmployeeName | EmployeeJoiningDate | +--------------+---------------------+ | David | 2019-09-28 11:10:50 | +--------------+---------------------+ 1 row in set (0.03 sec)