小编Soo*_*han的帖子

如何使用php从mysql表中对同一行中的年份和月份字段进行排序

我有一个包含月份和年份字段的mysql表,如下所示.

    year        month       filename                    filepath
    2013        Feb         2013Feb_Report.xlsx         ./main_reports/2013Feb_Report.xlsx
    2013        Jan         2013Jan_Report.xlsx         ./main_reports/2013Jan_Report.xlsx
    2012        Jul         2012Jul_Report.xlsx         ./main_reports/2012Jul_Report.xlsx
    2013        Mar         2013Mar_Report.xlsx         ./main_reports/2013Mar_Report.xlsx
    2011        Mar         monthly report180413.xlsx   ./main_reports/monthly report180413.xlsx
    2012        Sep         2012Sep_Report.xlsx         ./main_reports/2012Sep_Report.xlsx
    2012        Oct         2012Oct_Report.xlsx         ./main_reports/2012Oct_Report.xlsx
Run Code Online (Sandbox Code Playgroud)

我正在检索此表中的所有字段并将其打印如下.

    2011 Mar  :  monthly report180413.xlsx
    2012 Sep  :  2012Sep_Report.xlsx
    2012 Oct  :  2012Oct_Report.xlsx
    2013 Jan  :  2013Jan_Report.xlsx
Run Code Online (Sandbox Code Playgroud)

我想通过按DESC顺序对月份和年份字段进行排序来检索此表,如下所示.我怎样才能做到这一点?我应该更改月份和年份字段的数据类型吗?请帮忙..

    2013 Jan  :  2013Jan_Report.xlsx
    2012 Oct  :  2012Oct_Report.xlsx
    2012 Sep  :  2012Sep_Report.xlsx
    2011 Mar  :  monthly report180413.xlsx
Run Code Online (Sandbox Code Playgroud)

我使用的sql查询如下.它以DESC顺序检索年份和月份,但月份按DESC顺序排列,即'Jan'高于'Feb'.我需要的是'Jan'上面的'Feb'..

 "SELECT * FROM main_reports ORDER BY year DESC, …
Run Code Online (Sandbox Code Playgroud)

php mysql sql-order-by date-sorting

1
推荐指数
1
解决办法
4155
查看次数

标签 统计

date-sorting ×1

mysql ×1

php ×1

sql-order-by ×1