您可以使用having子句。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> AdmissionDate varchar(100) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('10/12/2017'); mysql> insert into DemoTable values('01/11/2018'); mysql> insert into DemoTable values('31/01/2019'); mysql> insert into DemoTable values('09/06/2019'); mysql> insert into DemoTable values('19/04/2019');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+---------------+ | AdmissionDate | +---------------+ | 10/12/2017 | | 01/11/2018 | | 31/01/2019 | | 09/06/2019 | | 19/04/2019 | +---------------+ 5 rows in set (0.00 sec)
以下是对STR_TO_DATE作为列的查询-
mysql> select STR_TO_DATE(AdmissionDate, '%d/%m/%Y') as newDate from DemoTable -> having newDate >= '2019-01-01';
输出结果
+------------+ | newDate | +------------+ | 2019-01-31 | | 2019-06-09 | | 2019-04-19 | +------------+ 3 rows in set (0.00 sec)