宇很可能是在寻找对FULL OUTER JOIN
SELECt coalesce(a.pre,b.pre), coalesce(a."year",b.year), coalesce(a.nb_a,0), coalesce(b.nb_b,0), coalesce(a.nb_a,0) + coalesce(b.nb_b,0) AS totalFROM table_a a full outer join table_b b on a.pre = b.pre and a.year = b.year; coalesce | coalesce | coalesce | coalesce | total----------+----------+----------+----------+------- 1 | 2013 | 0 | 1 | 1 1 | 2014 | 0 | 1 | 1 1 | 2017 | 1 | 0 | 1 2 | 2012 | 2 | 1 | 3 3 | 2014 | 2 | 0 | 2(5 rows)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)