MySQL查询从具有日期记录的表中获取最新日期
让我们首先创建一个表-
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)
热门推荐
4 狗狗请人训练
5 训练狗狗迎宾
6 训练狗狗解放
7 抬头训练狗狗
10 训练狗狗的基本动作
11 两个月狗狗怎么训练大小便
12 教狗狗训练
13 记叙文训练狗狗
14 潮州训练狗狗
15 训练狗狗叫的方法
16 猫训练狗狗
17 狗狗训练如厕
18 狗狗来训练