聚合查询后,一个ID 对应多个结果,拼接成一个字段
SELECT
ol.user_id,
array_to_string( ARRAY ( SELECT UNNEST ( ARRAY_AGG ( ol.org_id ) ) ORDER BY 1 ), ',' ) AS org_ids,
array_to_string( ARRAY ( SELECT UNNEST ( ARRAY_AGG ( oi.NAME ) ) ORDER BY 1 ), ',' ) AS org_names
FROM
( sys_user_org_relation ol LEFT JOIN sys_org_info oi ON ( ( ol.org_id = oi.ID ) ) )
GROUP BY
ol.user_id