下面是正常的查詢多條數據,如果我要合並成列怎么辦。

其實pg有自帶的array_to_string函數 ,但是寫法稍微有點麻煩,但是可以根據array_to_string函數自定義一個函數去簡化寫法。
CREATE AGGREGATE group_concat(anyelement)(
sfunc = array_append,
stype = anyarray,
initcond = '{}'
);
然后使用函數去指定字符串去分割就行了

pg9.x版本可以用函數string_agg實現
select string_agg(bm,'.') as codePath from table
oracle使用listagg函數實現
select listagg(bm,'.') WITHIN GROUP(ORDER BY bm) as cxmlj from table start with bm = '150203740000' connect by prior ssjgid = zzjgid
