MySQL按年/月/日排序 [英] MySQL sort on year/month/day

查看:468
本文介绍了MySQL按年/月/日排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的格式日期格式 dd-mm-yyyy。
所以我想订购:年,然后在月份

I have a large list of dates of the format dd-mm-yyyy. So I want to order on: year, then on month and then on day.

日期和月份在同一个字段中,年份是另一个字段。

Date and month are in the same field and year is an other field.

我有现在: ORDER BY table.year ASC,table.date ASC

结果是列表是在年,然后天。

如何拆分/剥离dd-mm格式,并在排序日期之前首先排序?

The result is that the list is order on year and then days.
How to split/strip the dd-mm format and first sort on month before sorting on days?

Same record:    
date | year   
dd-mm  | yyyy


推荐答案

根据您的示例,您可以对记录进行排序这个

based on your example you can sort the record like this,

ORDER BY STR_TO_DATE(CONCAT(year, '-', date), '%Y-%d-%m') ASC




  • SQLFiddle Demo

    • SQLFiddle Demo
    • 这篇关于MySQL按年/月/日排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆