📜  postgres 多个左连接导致重复 jsonb_agg - SQL 代码示例

📅  最后修改于: 2022-03-11 15:04:52.244000             🧑  作者: Mango

代码示例1
SELECT tbl_a.id, tbl_a.name,
       COALESCE( ( SELECT json_agg(tbl_b.*)
                     FROM tbl_b 
                    WHERE tbl_b.a_id = tbl_a.id ), '{}'::json),
       COALESCE( ( SELECT json_agg(tbl_c.*)
                     FROM tbl_c 
                    WHERE tbl_c.a_id = tbl_a.id ), '{}'::json)
  FROM tbl_a;