首先,我有4個表SQL全外連接多個表
Table0, Columns: num, desc Table1, Columns: num, qty1 Table2, Columns: num, qty2 Table3, Columns: num, qty3 Table4, Columns: num, qty4
(不是所有NUM在qty1或qty2或qty3或qty4值,所以我需要一個完整的連接) 和我的查詢:
SELECT Table0.num, SUM(Table1.qty1), SUM(Table2.qty2), SUM(Table3.qty3), SUM(Table4.qty4)
FROM Table0
FULL OUTER JOIN Table1 ON Table0.num = Table1.num
FULL OUTER JOIN Table2 ON Table0.num = Table2.num
FULL OUTER JOIN Table3 ON Table0.num = Table3.num
FULL OUTER JOIN Table4 ON Table0.num = Table4.num
GROUP BY Table0.num
不知怎的,它返回僅1行數據:
num | qty1 | qty2 | qty3 | qty4 | --------------------------------- | 100 | 20 | 77 | 969 |
但我期待像在
http://www.w3schools.com/sql/sql_join_full.asp
像例如:
num | qty1 | qty2 | qty3 | qty4 | --------------------------------- 1 | 0 | 2 | 3 | 2 | 2 | 1 | 0 | 0 | 0 | 3 | 7 | 0 | 9 | 0 | 4 | 0 | 0 | 0 | 10 | 5 | 0 | 0 | 7 | 0 | 6 | 8 | 2 | 9 | 3 | 7 | 0 | 1 | 0 | 0 |
(我不知道這個解決它) 但是我得到了類似的結果上方的框改變所有表:
Table1, Columns: num, qty1, qty2, qty3, qty4 Table2, Columns: num, qty2, qty1, qty3, qty4 Table3, Columns: num, qty3, qty1, qty2, qty4 Table4, Columns: num, qty4, qty1, qty2, qty3
這是相當令人印象深刻,它的所有,返回任何數據因爲MySQL不支持'FULL OUTER JOIN'。 – eggyal
需要向我們展示這些表中的行。它會出現Table0.num包含null或空白,而不是您所期望的值。 – AaronLS
Table0.num沒有空的空值 – user1618180