ejemplos - MySQL: ordenar valores de GROUP_CONCAT
group_concat mysql separator (2)
En resumen: ¿hay alguna manera de ordenar los valores en una declaración GROUP_CONCAT?
Consulta:
GROUP_CONCAT((SELECT GROUP_CONCAT(parent.name SEPARATOR " » ")
FROM test_competence AS node, test_competence AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND node.id = l.competence
AND parent.id != 1
ORDER BY parent.lft) SEPARATOR "<br />/n") AS competences
Obtengo esta fila:
Artesanía »Carpintería
Administración »Organización
Lo quiero así:
Administración »Organización
Artesanía »Carpintería
¿Quieres ordenar por?
SELECT _key,
COUNT(*) as cnt,
GROUP_CONCAT(_value ORDER BY _value SEPARATOR '', '') as value_list
FROM group_concat_test
GROUP BY _key
ORDER BY _key;
Claro, vea http://dev.mysql.com/doc/refman/...tions.html#function_group-concat :
SELECT student_name,
GROUP_CONCAT(DISTINCT test_score ORDER BY test_score DESC SEPARATOR '' '')
FROM student
GROUP BY student_name;