mysql - group_concat order
GROUP_CONCAT ORDER BY (4)
El group_concat admite su propia orden por cláusula
http://mahmudahsan.wordpress.com/2008/08/27/mysql-the-group_concat-function/
Entonces deberías poder escribir:
SELECT li.clientid, group_concat(li.views order by views) AS views,
group_concat(li.percentage order by percentage)
FROM table_views GROUP BY client_id
Tengo una mesa como esta:
+-----------+-------+------------+
| client_id | views | percentage |
+-----------+-------+------------+
| 1 | 6 | 20 |
| 1 | 4 | 55 |
| 1 | 9 | 56 |
| 1 | 2 | 67 |
| 1 | 7 | 80 |
| 1 | 5 | 66 |
| 1 | 3 | 33 |
| 1 | 8 | 34 |
| 1 | 1 | 52 |
Intenté group_concat
:
SELECT li.client_id, group_concat(li.views) AS views,
group_concat(li.percentage) FROM li GROUP BY client_id;
+-----------+-------------------+-----------------------------+
| client_id | views | group_concat(li.percentage) |
+-----------+-------------------+-----------------------------+
| 1 | 6,4,9,2,7,5,3,8,1 | 20,55,56,67,80,66,33,34,52 |
+-----------+-------------------+-----------------------------+
Pero quiero obtener los puntos de vista en orden, como:
+-----------+-------------------+----------------------------+
| client_id | views | percentage |
+-----------+-------------------+----------------------------+
| 1 | 1,2,3,4,5,6,7,8,9 | 52,67,33,55,66,20,80,34,56 |
+-----------+-------------------+----------------------------+
En IMPALA, no tener orden en GROUP_CONCAT puede ser problemático en Coders''Co. tenemos algún tipo de solución para eso (lo necesitamos para Rax / Impala). Si necesita el resultado GROUP_CONCAT con una cláusula ORDER BY en IMPALA, eche un vistazo a esta publicación del blog: http://raxdb.com/blog/sorting-by-regex/
Puede usar ORDER BY
dentro de la función GROUP_CONCAT
de esta manera:
SELECT li.client_id, group_concat(li.percentage ORDER BY li.views ASC) AS views,
group_concat(li.percentage ORDER BY li.percentage ASC)
FROM li GROUP BY client_id
Tratar
SELECT li.clientid, group_concat(li.views ORDER BY li.views) AS views, group_concat(li.percentage ORDER BY li.percentage) FROM table_views li GROUP BY client_id
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function%5Fgroup-concat