我有一张这样的桌子:
id | ciaps
1 | a|b|c
A有第二个表,如:
cod | desc
a | item a
b | item b
c | item c
我需要一个代码来连接这些表,如下所示:
id | ciaps
1 | item a|item b|item c
发布于 2021-09-03 10:05:41
使用array_agg连接由'|‘分隔的字符串,并将其转换为array_to_string,以获得所需的值格式。
-- PostgreSQL (v11)
SELECT t1.id, t2.descr ciaps
FROM test1 t1
INNER JOIN (SELECT array_to_string(array_agg(cod), '|') cod
, array_to_string(array_agg(descr), '|') descr
FROM test2) t2
ON t1.ciaps = t2.cod;
请从url https://dbfiddle.uk/?rdbms=postgres_11&fiddle=6fffc7f1da6a02a48018b3691c99ad17查看
https://stackoverflow.com/questions/69048736
复制