Multiple FULL OUTER JOIN on multiple tables

前端 未结 5 1944
暗喜
暗喜 2020-12-23 20:36

I have multiple outer joins

SELECT  A.column2
        , B.column2
        , C.column2
FROM 
(
    (SELECT month, column2 FROM table1) A
    FULL OUTER JOIN
          


        
5条回答
  •  旧时难觅i
    2020-12-23 21:07

    I can think of 2 ways off the bat that you can address this, depending on what the actual logic is to define the results you want.

    The first, and most fool-proof way, is to use GROUP BY month, and use aggregate functions like MAX(column2) to get the non-zero rows only, or if there are multiple non-zero rows you want to add, use SUM(). This is the best solution if there is an aggregate function that fulfills your logical intent.

    Another is to include more conditions in your JOIN, like "WHERE a.month=b.month AND b.column2 > 0", but that still won't solve the problem if there can be more than one non-zero row.

提交回复
热议问题