[英]Selecting and aggregating multiple rows in MySQL
I have a query that returns several rows that I'd like to group by a column. 我有一个查询,该查询返回要按列分组的几行。 So for example,
例如
title | label
--------------
may ny
may ct
june ma
june ri
How would I (efficiently) return 我将如何(有效地)返回
title | label
--------------
may ct,ny
june ma,ri
such that the ordering of the concatenation is alphabetical? 这样串联的顺序是字母顺序的?
Check the GROUP_CONCAT
function. 检查
GROUP_CONCAT
函数。 The query would be: 该查询将是:
SELECT title, GROUP_CONCAT(label ORDER BY label)
GROUP BY title
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.