如何 select MySql 中的最新日期?
How to select latest date in MySql?
|id | cont_no| date |
+---+--------+----------+
|1 | 1 |01-02-2011|
|2 | 1 |21-02-2011|
|3 | 2 |08-01-2011|
|4 | 1 |25-01-2011|
日期存储为 (dd-mm-yyyy) 格式,日期列为 varchar
现在我想 select 最新日期
我这样试过,但没用
SELECT FROM table_name where cont_no='1' AND top(date)
这是我期待的结果
|id | cont_no| date |
+---+--------+----------+
|1 | 1 |21-02-2011|
请有人帮助我
SELECT * FROM table_name order by date desc limit 1
SELECT cont_no,max(date) FROM table_name group by cont_no
如果您的日期是 char(x),您可以使用此查询:
SELECT * FROM table_name order by str_to_date(`date`, '%d-%m-%Y') desc limit 1
|id | cont_no| date |
+---+--------+----------+
|1 | 1 |01-02-2011|
|2 | 1 |21-02-2011|
|3 | 2 |08-01-2011|
|4 | 1 |25-01-2011|
日期存储为 (dd-mm-yyyy) 格式,日期列为 varchar
现在我想 select 最新日期
我这样试过,但没用
SELECT FROM table_name where cont_no='1' AND top(date)
这是我期待的结果
|id | cont_no| date |
+---+--------+----------+
|1 | 1 |21-02-2011|
请有人帮助我
SELECT * FROM table_name order by date desc limit 1
SELECT cont_no,max(date) FROM table_name group by cont_no
如果您的日期是 char(x),您可以使用此查询:
SELECT * FROM table_name order by str_to_date(`date`, '%d-%m-%Y') desc limit 1