让我们首先创建一个表-
mysql> create table DemoTable ( AdmissionDate varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Sunday, 11 August 2019'); mysql> insert into DemoTable values('Friday, 18 October 2019'); mysql> insert into DemoTable values('Thursday, 18 July 2019');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable ;
这将产生以下输出-
+-------------------------+ | AdmissionDate | +-------------------------+ | Sunday, 11 August 2019 | | Friday, 18 October 2019 | | Thursday, 18 July 2019 | +-------------------------+ 3 rows in set (0.00 sec)
以下是从上方插入的varchar日期列表中获取最大日期的查询-
mysql> select max(str_to_date(AdmissionDate,'%W, %d %M %Y')) AS MaxDate from DemoTable;
这将产生以下输出-
+------------+ | MaxDate | +------------+ | 2019-10-18 | +------------+ 1 row in set (0.04 sec)