查找MySQL中最低的日期(自定义)?

为了找到MySQL中最低的Date(custom),让我们首先创建一个表。创建表的查询如下:

mysql> create table FindMinimumDate
   -> (
   -> Id int NOT NULL AUTO_INCREMENT,
   -> yourDay varchar(2),
   -> yourMonth varchar(2),
   -> yourYear varchar(4),
   -> PRIMARY KEY(Id)
   -> );

使用insert命令在表中插入一些记录。查询如下:

mysql> insert into FindMinimumDate(yourDay,yourMonth,yourYear) values('21','11','2019');

mysql> insert into FindMinimumDate(yourDay,yourMonth,yourYear) values('20','10','2020');

mysql> insert into FindMinimumDate(yourDay,yourMonth,yourYear) values('03','08','2014');

mysql> insert into FindMinimumDate(yourDay,yourMonth,yourYear) values('04','09','2017');

mysql> insert into FindMinimumDate(yourDay,yourMonth,yourYear) values('05','07','2013');

mysql> insert into FindMinimumDate(yourDay,yourMonth,yourYear) values('25','12','2016');

使用select语句显示表中的所有记录。查询如下:

mysql> select *from FindMinimumDate;

以下是输出:

+----+---------+-----------+----------+
| Id | yourDay | yourMonth | yourYear |
+----+---------+-----------+----------+
|  1 | 21      | 11        | 2019     |
|  2 | 20      | 10        | 2020     |
|  3 | 03      | 08        | 2014     |
|  4 | 04      | 09        | 2017     |
|  5 | 05      | 07        | 2013     |
|  6 | 25      | 12        | 2016     |
+----+---------+-----------+----------+
6 rows in set (0.00 sec)

现在让我们找到MySQL中最低的Date(Custom)。查询如下:

mysql> select min(concat(yourYear,'-',yourMonth,'-',yourDay)) as MinimumDate from FindMinimumDate;

以下是显示最低日期的输出:

+-------------+
| MinimumDate |
+-------------+
| 2013-07-05  |
+-------------+
1 row in set (0.00 sec)