GROUP_CONCAT无法按顺序排序

时间:2021-12-21 21:09:26

I can't make GROUP_CONCAT make ORDER BY.

我无法使GROUP_CONCAT成为ORDER BY。

SELECT GROUP_CONCAT(`cdlAmountA`+`cdlAmountB`+`cdlAmountC` SEPARATOR "|")
     FROM `creditlogs`
     WHERE `cdlDate` = "2016-04-07"
          AND compID = "AIR"
     ORDER BY `creditID`

This is out put.

这是出局。

96276.9|7960.2|0|0

But it's not right, The right answer is.

但这不对,正确的答案是。

0|96276.9|7960.2|0

How can i make it right. And this is database.

我怎样才能做对。这是数据库。

creditID | cdlAmountA | cdlAmountB | cdlAmountC
-----------------------------------------------
1        | 0          | 0          | 0
2        | 34948.7    | 61328.2    | 0
3        | 4510.2     | 3450       | 0  
4        | 0          | 0          | 0

1 个解决方案

#1


1  

The ORDER BY clause has to be used inside GROUP_CONCAT function like this:

ORDER BY子句必须在GROUP_CONCAT函数中使用,如下所示:

SELECT GROUP_CONCAT(`cdlAmountA`+`cdlAmountB`+`cdlAmountC` 
                    ORDER BY `creditID` SEPARATOR "|" )
FROM `creditlogs`
WHERE `cdlDate` = "2016-04-07" AND compID = "AIR"

Demo here

#1


1  

The ORDER BY clause has to be used inside GROUP_CONCAT function like this:

ORDER BY子句必须在GROUP_CONCAT函数中使用,如下所示:

SELECT GROUP_CONCAT(`cdlAmountA`+`cdlAmountB`+`cdlAmountC` 
                    ORDER BY `creditID` SEPARATOR "|" )
FROM `creditlogs`
WHERE `cdlDate` = "2016-04-07" AND compID = "AIR"

Demo here