MySQL查询选择两个日期范围之间的所有数据?
要选择两个日期范围之间的所有数据,请使用MySQL BETWEEN-
select * from yourTableName where yourColumnName between yourDateValue1 and yourDateValue2;
让我们首先创建一个-
mysql> create table DemoTable1422-> (
-> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> EmployeeName varchar(20),
-> EmployeeJoiningDate date
-> );
使用insert在表中插入一些记录-
mysql> insert into DemoTable1422(EmployeeName,EmployeeJoiningDate) values('John','2017-09-28');mysql> insert into DemoTable1422(EmployeeName,EmployeeJoiningDate) values('Chris','2019-09-29');
mysql> insert into DemoTable1422(EmployeeName,EmployeeJoiningDate) values('Bob','2018-01-31');
mysql> insert into DemoTable1422(EmployeeName,EmployeeJoiningDate) values('Sam','2018-12-21');
mysql> insert into DemoTable1422(EmployeeName,EmployeeJoiningDate) values('Mike','2019-11-10');
使用选择显示表中的所有记录-
mysql> select * from DemoTable1422;
这将产生以下输出-
+------------+--------------+---------------------+| EmployeeId | EmployeeName | EmployeeJoiningDate |
+------------+--------------+---------------------+
| 1 | John | 2017-09-28 |
| 2 | Chris | 2019-09-29 |
| 3 | Bob | 2018-01-31 |
| 4 | Sam | 2018-12-21 |
| 5 | Mike | 2019-11-10 |
+------------+--------------+---------------------+
5 rows in set (0.00 sec)
以下是查询以选择两个日期范围之间的所有数据-
mysql> select * from DemoTable1422 where EmployeeJoiningDate between '2018-09-29' and '2019-09-29';
这将产生以下输出-
+------------+--------------+---------------------+| EmployeeId | EmployeeName | EmployeeJoiningDate |
+------------+--------------+---------------------+
| 2 | Chris | 2019-09-29 |
| 4 | Sam | 2018-12-21 |
+------------+--------------+---------------------+
2 rows in set (0.00 sec)
以上是 MySQL查询选择两个日期范围之间的所有数据? 的全部内容, 来源链接: utcz.com/z/348814.html