[英]Add prefix with distinct in group_concat sql
Hey I have this query嘿,我有这个问题
select group_concat(distinct(accountId) separator "' ,")
from xxx_yyy_replacement_instances
where deletedAt IS NULL
which returns me the next results这将返回我的下一个结果
act-fdf4caf8' ,act-525d62af' ,act-e141e6ab' ,act-73995962' ,act-c782e06d' ,act-993aaec0' ,act-1a2f883e' ,act-ed6f5f9e
I want add "'"
before each accountId我想在每个 accountId 之前添加
"'"
I used concat inside but then it can't get the distinct(accountId), I used also我在里面使用了 concat 但它无法获得 distinct(accountId),我也使用过
select group_concat(",",distinct(accountId) separator "' ,")
from gcp_gce_replacement_instances
where deletedAt IS NULL
But I get an error with it.但我得到了一个错误。
The desired result is : 'act-fdf4caf8','act-525d62af','act-e141e6ab','act-73995962','act-c782e06d','act-993aaec0','act-1a2f883e','act-ed6f5f9e'
期望的结果是:
'act-fdf4caf8','act-525d62af','act-e141e6ab','act-73995962','act-c782e06d','act-993aaec0','act-1a2f883e','act-ed6f5f9e'
Don't put the second '
in the SEPARATOR
, concatenate both of them with the account ID.不要将第二个
'
放在SEPARATOR
中,将它们与帐户 ID 连接起来。
You don't need to call CONCAT()
explicitly.您不需要显式调用
CONCAT()
。 You can put multiple values in the GROUP_CONCAT()
arguments and they'll be concatenated.您可以在
GROUP_CONCAT()
参数中放置多个值,它们将被连接起来。
SELECT GROUP_CONCAT(DISTINCT "'", accountId, "'" SEPARATOR ', ')
FROM gcp_gce_replacement_instances
WHERE deletedAt IS NULL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.