选择 MySQL 中比当前日期旧的行?
假设当前日期为 2019-08-03。现在,我们来看一个示例并创建一个表 -
mysql> create table DemoTable840(DueDate datetime); Query OK, 0 rows affected (0.66 sec)
使用插入命令在表中插入一些记录 -
mysql> insert into DemoTable840 values('2019-08-9'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable840 values('2019-07-5'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable840 values('2019-08-10'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable840 values('2019-07-13'); Query OK, 1 row affected (0.10 sec)
使用 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)
广告