查询中的ORDER BY与复合字段

时间:2014-04-09 14:24:33

标签: mysql sql

我有下一个mysql表结构:

++++++++++++++++++++++++++++++++++++
+ id + value + month + year + type +
++++++++++++++++++++++++++++++++++++

我想做下一个选择:

SELECT 
 * 
FROM 
 Table

但是ORDER BY选项。我想在YEAR-MONTH复合字段DESC上对结果进行排序。

我需要这样的东西:

SELECT 
 * 
FROM 
 Table
ORDER BY 
 YEAR-MONTH
DESC

我怎么能这样做?

2 个答案:

答案 0 :(得分:5)

SELECT 
    * 
FROM 
    Table
ORDER BY 
    YEAR DESC, 
    MONTH DESC

答案 1 :(得分:0)

SELECT CONCAT( year, month ) AS _sorter, *
FROM table
ORDER BY _sorter