如何在MySQL中连接结果集? [英] How can I concatenate set of results in MySQL?
本文介绍了如何在MySQL中连接结果集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用逗号作为分隔符来连接MySQL中返回的结果.
I would like to join results returned in the set in MySQL with a comma as a separator string.
例如,返回的set包含:
For example, set returned contains:
COLUMN_X
john
jerry
maria
joseph
gugla
我希望收到的结果是:
COLUMN_X-concat
john,jerry,maria,joseph,gugla
有可能吗?谢谢.
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.
推荐答案
SELECT GROUP_CONCAT(COLUMN_X SEPARATOR ',') FROM <<table>> GROUP BY NULL
请参见 GROUP_CONCAT
.
See GROUP_CONCAT
.
这篇关于如何在MySQL中连接结果集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文