MySQL GROUP_CONCAT,双订单由

MySQL GROUP_CONCAT,双订单由,mysql,sql-order-by,group-concat,Mysql,Sql Order By,Group Concat,我有一个组,我需要按2列排序。问题是,对于我将在任何其他orderby中使用的普通sintax,它将只忽略第二列的第一列排序 例如: GROUP_CONCAT( DC.reference_date,' - ',D.number,'/',D.year,' : ', IF(DC.notes IS NOT NULL,DC.notes,'') ORDER BY D.number, DC.reference_date SEPARATOR '\r\n' ) 有了这个,我将得到一个按

我有一个组,我需要按2列排序。问题是,对于我将在任何其他orderby中使用的普通sintax,它将只忽略第二列的第一列排序

例如:

GROUP_CONCAT(
    DC.reference_date,' - ',D.number,'/',D.year,' : ',
    IF(DC.notes IS NOT NULL,DC.notes,'')
    ORDER BY D.number, DC.reference_date SEPARATOR '\r\n'
)
有了这个,我将得到一个按日期排序的列表,而不是按编号,然后按日期排序:

2015-05-25 - 3714/2014 : id 17
2015-05-25 - 2729/2014 : id 19
2015-05-27 - 3714/2014 : id 21
2015-05-27 - 2729/2014 : id 20
2015-05-28 - 3714/2014 : id 18
因此:

GROUP_CONCAT(
    DC.reference_date,' - ',D.number,'/',D.year,' : ',
    IF(DC.notes IS NOT NULL,DC.notes,'')
    ORDER BY D.number SEPARATOR '\r\n'
)
我仅按编号正确地获取列表:

2015-05-27 - 3714/2014 : id 21
2015-05-28 - 3714/2014 : id 18
2015-05-25 - 3714/2014 : id 17
2015-05-27 - 2729/2014 : id 20
2015-05-25 - 2729/2014 : id 19
我需要的是这样的列表顺序:

2015-05-25 - 3714/2014 : id 17
2015-05-27 - 3714/2014 : id 21
2015-05-28 - 3714/2014 : id 18
2015-05-25 - 2729/2014 : id 19
2015-05-27 - 2729/2014 : id 20
有没有线索说明为什么ORDER BY失败了

根据草莓请求更新,以下是整个查询的简化版本:

SELECT GROUP_CONCAT(DC.reference_date,' - ',D.number,'/',D.year,' : ', IF(DC.notes IS NOT NULL,DC.notes,'') ORDER BY D.number SEPARATOR '\r\n') AS 'd_c', CD.contract_id
FROM gbdc AS DC
LEFT JOIN [...]
WHERE CD.cancel <> 1
AND BP.bill_id IS NULL
GROUP BY CD.contract_id

我在ORDER BY子句中看不出有什么不同。@TravisG我只是复制了相同的东西,我同意,它们是相同的。@TravisG我的错,我复制并粘贴了相同的代码片段。现在,我已经更新了.Erm,order by number desc,date。您确定在第二个示例中列表的顺序正确吗?查询按D.number读取顺序无排序方向,默认为ASC,但D.number的值为3714…2729,即降序。