SQL查询:订单月份

时间:2014-08-22 04:29:52

标签: php mysql sql

monthName   year    total

August     2014     10000
July       2014     20000
June       2014     56400
October    2015     20000
September  2014     23400
September  2015     10000

我想在月份和年份订单中订购以上数据,如下所示

monthName  year    total

June       2014    56400
July       2014    20000
August     2014    10000
September  2014    23400
September  2015    10000
Octomber   2015    20000

订单(Januery,2月,3月,2014年和2015年数据)

我使用以下查询

SELECT * FROM chartdraw GROUP BY monthName

但是我喜欢打击

monthName   year       total

August      2014       10000
July        2014       20000
June        2014       56400
October     2015       20000
September   2014       23400

你能帮我解决这个问题吗?

3 个答案:

答案 0 :(得分:0)

SELECT * FROM chartdraw  ORDER BY DATEPART(MM, concat_ws(" ",monthname,year,01))

答案 1 :(得分:0)

请尝试:

order by
    str_to_date(concat('1',`monthName`,`year`),'%e %M %Y')

答案 2 :(得分:0)

尝试此查询,我认为这正是您所需要的。

SELECT * FROM chartdraw order by DATEPART(mm,CAST([MONTH]+ ' 1900' AS DATETIME)) asc