How do I concat grouped rows as a single row in MySQL?
I have a query like SELECT CONCAT(manufacturer, ':', COUNT(*)) AS count FROM cars GROUP BY manufacturer
which returns something like:
+---------+
| count |
+---------+
| ford:10 |
| fiat:5 |
| kia:2 |
+---------+
Now I want to GROUP_CONCAT those r开发者_JS百科ows into 1 row like:
+------------------------+
| result |
+------------------------+
| ford:10, fiat:5, kia:2 |
+------------------------+
But there's already a GROUP BY, so GROUP_CONCAT doesn't work. How can I achieve this with MySQL?
select Group_Concat(count SEPERATOR ',') from
(SELECT CONCAT(manufacturer, ':', COUNT(*)) AS count
FROM cars GROUP BY manufacturer) AS A
精彩评论