让我们首先创建一个表-
mysql> create table DemoTable ( DueDate date );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('2018-10-01'); mysql> insert into DemoTable values('2016-12-31'); mysql> insert into DemoTable values('2019-07-02'); mysql> insert into DemoTable values('2015-01-12'); mysql> insert into DemoTable values('2019-04-26');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+------------+ | DueDate | +------------+ | 2018-10-01 | | 2016-12-31 | | 2019-07-02 | | 2015-01-12 | | 2019-04-26 | +------------+ 5 rows in set (0.00 sec)
假设当前日期为2019-08-15。现在我们将获取最新日期-
mysql> select *from DemoTable order by DueDate DESC limit 1;
这将产生以下输出-
+------------+ | DueDate | +------------+ | 2019-07-02 | +------------+ 1 row in set (0.03 sec)