简体   繁体   English

Group_concat()不根据数据排序

[英]Group_concat() not sorting according to the data

Sorted data is what I want and I am not getting it from this order by clause addition to this statement. 排序后的数据正是我想要的,并且我无法从该语句的按子句添加顺序中获得该数据。

SELECT
    GROUP_CONCAT(DISTINCT
        CONCAT(
            'COUNT((CASE WHEN (`ltd`.`total_pass_pc` =',total_pass_pc,') THEN 1 ELSE NULL END)) AS `TC=',total_pass_pc,'`'
        )
    )INTO @sql
    FROM log_tc_data
    ORDER BY `total_pass_pc`;

the results that this group_concat produce for total_pass_pc is in order 0 11.1111111 80 33.33333........not sorted I want to sort it 0 11.11111 33.333333 80......sorted order 结果,这group_concat用于生产total_pass_pc是为了0 11.1111111 80 33.33333 ........没有排序我想0 11.11111 33.333333 80排序呢......的排序顺序

here is the screen shot of its result 这是其结果的屏幕截图

http://postimg.org/image/yywctdpj3/7cc79088/ http://postimg.org/image/yywctdpj3/7cc79088/

You need a define a GROUP BY clause so that while selecting data the records will be grouped relative to this column name. 您需要定义GROUP BY子句,以便在选择数据时,记录将相对于此列名进行分组。 And to sort it you can use ORDER BY inside GROUP_CONCAT Try this: 要对其进行排序,可以在GROUP_CONCAT内使用ORDER BY尝试以下操作:

SELECT
GROUP_CONCAT(DISTINCT CONCAT('COUNT((CASE WHEN (`ltd`.`total_pass_pc`=',total_pass_pc,') THEN 1 ELSE NULL END)) AS `TC=',total_pass_pc,'`')
  ORDER BY `total_pass_pc`)INTO @sql

FROM log_tc_data;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM