我有一个像SELECT CONCAT(manufacturer, ':', COUNT(*)) AS count FROM cars GROUP BY manufacturer
这样的查询,它返回的内容如下:
+---------+
| count |
+---------+
| ford:10 |
| fiat:5 |
| kia:2 |
+---------+
现在我想把这些行GROUP_CONCAT分成1行,如:
+------------------------+
| result |
+------------------------+
| ford:10, fiat:5, kia:2 |
+------------------------+
但是已经有了GROUP BY,所以GROUP_CONCAT不起作用。我怎样才能用MySQL实现这个目标?
答案 0 :(得分:3)
select Group_Concat(count SEPERATOR ',') from
(SELECT CONCAT(manufacturer, ':', COUNT(*)) AS count
FROM cars GROUP BY manufacturer) AS A