2011-04-15 51 views
1

我有一個像SELECT CONCAT(manufacturer, ':', COUNT(*)) AS count FROM cars GROUP BY manufacturer查詢返回是這樣的:如何在MySQL中將分組行連接爲單行?

+---------+ 
| count | 
+---------+ 
| ford:10 | 
| fiat:5 | 
| kia:2 | 
+---------+ 

現在我想那些行GROUP_CONCAT成1行,如:

+------------------------+ 
| result     | 
+------------------------+ 
| ford:10, fiat:5, kia:2 | 
+------------------------+ 

但已經有一個GROUP BY,所以GROUP_CONCAT沒有按」工作。我如何用MySQL實現這一目標?

回答

3
select Group_Concat(count SEPERATOR ',') from 
(SELECT CONCAT(manufacturer, ':', COUNT(*)) AS count 
FROM cars GROUP BY manufacturer) AS A 
+0

很好,謝謝! – 2011-04-15 20:22:35