一尘不染

MySQL:对GROUP_CONCAT值进行排序

mysql

简而言之:有什么方法可以对GROUP_CONCAT语句中的值进行排序吗?

查询:

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

我得到这一行:

工艺品»细木工

行政管理»组织

我想要这样:

行政管理»组织

工艺品»细木工


阅读 353

收藏
2020-05-17

共1个答案

一尘不染

当然,请参见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;
2020-05-17