다음은 구문입니다 -
select *from yourTableName where yourColumnName1 < yourValue1 AND (yourColumnName2 > yourValue2 OR yourColumnName2 is null);
테이블을 만들어 봅시다 -
mysql> create table demo35 −> ( −> id int NOT NULL AUTO_INCREMENT PRIMARY KEY, −> joining_date date, −> relieving_date date −> ); Query OK, 0 rows affected (3.88 sec)
insert 명령을 사용하여 일부 레코드를 테이블에 삽입하십시오 -
mysql> insert into demo35(joining_date,relieving_date) values('2020−01−10','2020−07−11'); Query OK, 1 row affected (0.15 sec) mysql> insert into demo35(joining_date,relieving_date) values('2020−05−07','2020−12−08'); Query OK, 1 row affected (0.17 sec) mysql> insert into demo35(joining_date,relieving_date) values('2020−04−11','2020−09−18'); Query OK, 1 row affected (0.14 sec) mysql> insert into demo35(joining_date,relieving_date) values('2020−03−12','2020−10−01'); Query OK, 1 row affected (0.13 sec)
select 문을 사용하여 테이블의 레코드 표시 -
mysql> select *from demo35;
이것은 다음과 같은 출력을 생성합니다 -
+----+--------------+----------------+ | id | joining_date | relieving_date | +----+--------------+----------------+ | 1 | 2020−01−10 | 2020−07−11 | | 2 | 2020−05−07 | 2020−12−08 | | 3 | 2020−04−11 | 2020−09−18 | | 4 | 2020−03−12 | 2020−10−01 | +----+--------------+----------------+ 4 rows in set (0.00 sec)
다음은 MySQL에서 조건부로 날짜를 선택하는 쿼리입니다 -
mysql> select *from demo35 −> where −> joining_date < '2020−05−11' AND −> (relieving_date > '2020−08−10' OR relieving_date is null);
이것은 다음과 같은 출력을 생성합니다 -
+----+--------------+----------------+ | id | joining_date | relieving_date | +----+--------------+----------------+ | 2 | 2020−05−07 | 2020−12−08 | | 3 | 2020−04−11 | 2020−09−18 | | 4 | 2020−03−12 | 2020−10−01 | +----+--------------+----------------+ 3 rows in set (0.00 sec)