我有 table - 检查日期

结构是...

Curr_date  
 
 150120 
 160120 
 170120 
 180120 

(日期格式为 DDMMYY )

只有单列存在,即 '主键'

现在我想获取保存在表中的最新日期或当前日期(其中 不会 总是最后一行)

例子:
最新添加日期为:010122

然后,记录将显示为...
 
Curr_date 
 
010122        <--- The Latest date is on the top 
150120 
160120 
170120 
 
 

Now how to fetch the Last Added Row in MySQL ? In this Scenario ?



(注意: select TOP 1 * from table_name order by Id desc ,不起作用......而且我想在没有 ID 列的情况下工作......)

编辑:数据类型是字符串

请您参考如下方法:

假设 curr_date 的数据类型是字符串。以下查询对您有用。

select curr_date 
       , STR_TO_DATE(curr_date,'%d%m%Y')  
from test  
order by STR_TO_DATE(curr_date,'%d%m%Y') desc; 


评论关闭
IT干货网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!