2009-06-15 139 views
139

簡而言之:是否有任何方法可以對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 

我得到該行:

工藝品»木工

管理»組織

我希望它是這樣的:

管理»組織

工藝品»木工

+0

也http://stackoverflow.com/q/8631210/632951 – Pacerier 2015-04-30 20:56:14

回答

16

你的意思是通過訂購?

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;