在MySQL中选择比当前日期早的行?
假设当前日期为2019-08-03。现在,我们将看到一个示例并创建一个表-
mysql> create table DemoTable840(DueDate datetime);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable840 values('2019-08-9'); mysql> insert into DemoTable840 values('2019-07-5'); mysql> insert into DemoTable840 values('2019-08-10'); mysql> insert into DemoTable840 values('2019-07-13');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable840;
这将产生以下输出-
+-----------------------+ | DueDate | +-----------------------+ | 2019-08-09 00 −00 −00 | | 2019-07-05 00 −00 −00 | | 2019-08-10 00 −00 −00 | | 2019-07-13 00 −00 −00 | +-----------------------+ 4 rows in set (0.00 sec)
以下是查询以选择比MySQL中当前日期早的行-
mysql> select *from DemoTable840 where DueDate < NOW();
这将产生以下输出-
+-----------------------+ | DueDate | +-----------------------+ | 2019-07-05 00 −00 −00 | | 2019-07-13 00 −00 −00 | +-----------------------+ 2 rows in set (0.00 sec)