GROUP_CONCAT 逗号分隔符 - MySQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7691816/
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
GROUP_CONCAT comma separator - MySQL
提问by user984580
I have a query where I am using GROUP_CONCAT
and a custom separator as my results may contain commas: '----'
我有一个我正在使用的查询GROUP_CONCAT
和一个自定义分隔符,因为我的结果可能包含逗号:'----'
This all works well, however it is still comma separated, so my output is:
这一切都很好,但它仍然是逗号分隔的,所以我的输出是:
Result A----,Result B----,Result C----
How can I make it so the output is:
我怎样才能做到这一点,所以输出是:
Result A----Result B----Result C----
I thought this was the idea of a custom separator!
我以为这是自定义分隔符的想法!
Failing that, can you escape commas in your results, so I can explode in PHP by the GROUP_CONCAT
commas?
如果做不到这一点,您能否在结果中转义逗号,以便我可以在 PHP 中通过GROUP_CONCAT
逗号爆炸?
回答by Joe Stefanelli
Looks like you're missing the SEPARATOR keyword in the GROUP_CONCATfunction.
看起来您在GROUP_CONCAT函数中缺少 SEPARATOR 关键字。
GROUP_CONCAT(artists.artistname SEPARATOR '----')
The way you've written it, you're concatenating artists.artistname
with the '----'
string using the default comma separator.
你写它的方式,你串联artists.artistname
与'----'
使用默认的逗号分隔符的字符串。
回答by Vallabh Bothre
Query to achieve your requirment
查询以达到您的要求
SELECT id,GROUP_CONCAT(text SEPARATOR ' ') AS text FROM table_name group by id;
回答by Roman
Or, if you are doing a split - join:
或者,如果您正在进行拆分 - 加入:
GROUP_CONCAT(split(thing, " "), '----') AS thing_name,
You may want to inclue WITHIN RECORD
, like this:
你可能想包括WITHIN RECORD
,像这样:
GROUP_CONCAT(split(thing, " "), '----') WITHIN RECORD AS thing_name,
from BigQuery API page