PostgreSql 连表查询行转列集合部分JSON化

SELECT 
    C.*,
    array_to_json(array_agg(row_to_json(n))) as node
FROM
    tb_green_channel
    C LEFT JOIN tb_green_channel_nodes cn ON C.ID = cn.channel_id
    LEFT JOIN tb_green_channel_node n ON cn.node_id = n."id" 
    GROUP BY c.id

image.png

你可能感兴趣的:(PostgreSql 连表查询行转列集合部分JSON化)