mysql - 如何在 MySql 中按日期顺序显示最近添加的数据?
问题描述
我希望按日期顺序对表格进行排序,以便最近添加的数据位于表格顶部。
我使用查询排序为:
select date from register_table order by date desc.
当前表格显示数据为:
date
02.04.2019
05.04.2019
09.04.2019
10.04.2019
06.02.2019
23.01.2019
11.01.2019
我希望我的表格显示为:
date
10.04.2019
09.04.2019
05.04.2019
02.04.2019
06.02.2019
23.01.2019
11.01.2019
如何按日期顺序显示数据?
解决方案
您的基本问题是不将日期存储为date
. 你应该解决这个问题。
要使查询正常工作,请使用:
order by str_to_date(date, '%m.%d.%Y')
要修复数据,您可以执行以下操作:
update register_table
set date = str_to_date(date, '%m.%d.%Y');
alter table register_table
modify date date;
你可以在这里看到它是如何工作的。
推荐阅读
- r - 在 R 中创建一个 2D 网格或栅格,将所有受访者与所有变量进行比较
- javascript - 将 js 组件导入 Angular 5
- xilinx-ise - Xilinx 14.7 许可证配置管理器未运行
- aws-api-gateway - 使用 AWS API Gateway 的两种方式 SSL
- j - J中秩的概念
- oauth - PHP Google Adwords API 获取广告系列
- reactjs - 与 React 一起使用时,FaceBook 评论插件无法正确显示
- unreal-engine4 - 有没有办法将已经制作的蓝图转换为虚幻中另一个 BP 的子类?
- c# - Entity Framework Core 包括加载额外的导航属性
- python-3.x - 使用比较运算符查找数据框列中的局部最大值