postgresql某字段存多个id,然后根据id连表查询


--buyer_id即为多id字段,id间通过逗号分隔

SELECT
array_to_json(array_agg(row_to_json(T))) as buyer
FROM
(
SELECT
company_id,
company_name_cn,
company_status_id
FROM
company_profile
WHERE
company_id IN(
SELECT
regexp_split_to_table(buyer_id, ',')
FROM
model_1
)
) T