开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜