在 MySQL 中查找最低日期(自定义)?
要找到 MySQL 中的最低 Date(自定义),我们首先创建一个表格。创建表格的查询如下。
mysql> create table FindMinimumDate -> ( -> Id int NOT NULL AUTO_INCREMENT, -> yourDay varchar(2), -> yourMonth varchar(2), -> yourYear varchar(4), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.57 sec)
使用插入命令在表格中插入一些记录。查询如下。
mysql> insert into FindMinimumDate(yourDay,yourMonth,yourYear) values('21','11','2019'); Query OK, 1 row affected (0.10 sec) mysql> insert into FindMinimumDate(yourDay,yourMonth,yourYear) values('20','10','2020'); Query OK, 1 row affected (0.38 sec) mysql> insert into FindMinimumDate(yourDay,yourMonth,yourYear) values('03','08','2014'); Query OK, 1 row affected (0.17 sec) mysql> insert into FindMinimumDate(yourDay,yourMonth,yourYear) values('04','09','2017'); Query OK, 1 row affected (0.12 sec) mysql> insert into FindMinimumDate(yourDay,yourMonth,yourYear) values('05','07','2013'); Query OK, 1 row affected (0.12 sec) mysql> insert into FindMinimumDate(yourDay,yourMonth,yourYear) values('25','12','2016'); Query OK, 1 row affected (0.08 sec)
使用选择语句显示表格中的所有记录。查询如下。
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(自定义)。查询如下。
mysql> select min(concat(yourYear,'-',yourMonth,'-',yourDay)) as MinimumDate from FindMinimumDate;
以下是显示最低日期的输出。
+-------------+ | MinimumDate | +-------------+ | 2013-07-05 | +-------------+ 1 row in set (0.00 sec)
广告