让我们首先创建一个表-
mysql> create table DemoTable1877 ( DueDate datetime );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1877 values('2019-12-10'); mysql> insert into DemoTable1877 values('2019-12-05'); mysql> insert into DemoTable1877 values('2019-12-07'); mysql> insert into DemoTable1877 values('2019-12-09');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1877;
这将产生以下输出-
+---------------------+ | DueDate | +---------------------+ | 2019-12-10 00:00:00 | | 2019-12-05 00:00:00 | | 2019-12-07 00:00:00 | | 2019-12-09 00:00:00 | +---------------------+ 4 rows in set (0.00 sec)
当前日期如下-
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-12-08 | +------------+ 1 row in set (0.00 sec)
这是选择小于当前日期的日期的查询-
mysql> select * from DemoTable1877 where DueDate < now();
这将产生以下输出-
+---------------------+ | DueDate | +---------------------+ | 2019-12-05 00:00:00 | | 2019-12-07 00:00:00 | +---------------------+ 2 rows in set (0.00 sec)