如何在 MySQL 中连接一组结果?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1728417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:30:15  来源:igfitidea点击:

How can I concatenate set of results in MySQL?

mysqlsetconcatenation

提问by dusoft

I would like to join results returned in the set in MySQL with a comma as a separator string.

我想用逗号作为分隔符字符串加入 MySQL 集合中返回的结果。

For example, set returned contains:

例如,返回的集合包含:

COLUMN_X
john
jerry
maria
joseph
gugla

I would like to receive the result as:

我希望得到的结果是:

COLUMN_X-concat
john,jerry,maria,joseph,gugla

is that possible? thanks.

那可能吗?谢谢。

SELECT CONCAT(rooms.ID,",") FROM rooms AS rooms LEFT JOIN inter AS i ON rooms.ID=i.value WHERE xxx=999

doesn't work as I would like it to as it returns separate results.

不能像我希望的那样工作,因为它返回单独的结果。

回答by Stefan Gehrig

SELECT GROUP_CONCAT(COLUMN_X SEPARATOR ',') FROM <<table>> GROUP BY NULL

See GROUP_CONCAT.

GROUP_CONCAT