먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable(DueDate datetime); Query OK, 0 rows affected (0.94 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable values('2019-07-10 04:20:00'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-07-10 05:10:40'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-07-10 09:00:20'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-07-10 10:01:04'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('2019-07-10 12:11:10'); Query OK, 1 row affected (0.19 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select *from DemoTable;
이것은 다음과 같은 출력을 생성합니다 -
+---------------------+ | DueDate | +---------------------+ | 2019-07-10 04:20:00 | | 2019-07-10 05:10:40 | | 2019-07-10 09:00:20 | | 2019-07-10 10:01:04 | | 2019-07-10 12:11:10 | +---------------------+ 5 rows in set (0.00 sec)
다음은 현재 날짜로 필터링하는 쿼리입니다 -
mysql> select *from DemoTable where date(DueDate)=curdate() and time(DueDate) > '04:00:00' and time(DueDate) < '10:00:00';
이것은 다음과 같은 출력을 생성합니다 -
+---------------------+ | DueDate | +---------------------+ | 2019-07-10 04:20:00 | | 2019-07-10 05:10:40 | | 2019-07-10 09:00:20 | +---------------------+ 3 rows in set (0.00 sec)