[英]Add prefix with distinct in group_concat sql
嘿,我有这个问题
select group_concat(distinct(accountId) separator "' ,")
from xxx_yyy_replacement_instances
where deletedAt IS NULL
这将返回我的下一个结果
act-fdf4caf8' ,act-525d62af' ,act-e141e6ab' ,act-73995962' ,act-c782e06d' ,act-993aaec0' ,act-1a2f883e' ,act-ed6f5f9e
我想在每个 accountId 之前添加"'"
我在里面使用了 concat 但它无法获得 distinct(accountId),我也使用过
select group_concat(",",distinct(accountId) separator "' ,")
from gcp_gce_replacement_instances
where deletedAt IS NULL
但我得到了一个错误。
期望的结果是: 'act-fdf4caf8','act-525d62af','act-e141e6ab','act-73995962','act-c782e06d','act-993aaec0','act-1a2f883e','act-ed6f5f9e'
不要将第二个'
放在SEPARATOR
中,将它们与帐户 ID 连接起来。
您不需要显式调用CONCAT()
。 您可以在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.