我有多个外连接
SELECT A.column2
, B.column2
, C.column2
FROM
(
(SELECT month, column2 FROM table1) A
FULL OUTER JOIN
(SELECT month, column2 FROM table2) B on A.month= B.month
FULL OUTER JOIN
(SELECT month, column2 FROM table3) C on A.month= C.month
)
现在最后一个连接存在问题,当A的月份大于B时它会重复,但是如果B有比A更多的月份我们在C中使用A的月份进行外连接,现在会出现重复,所以我猜想在两个表之间进行全外连接可能会解决这个问题?有什么深入的链接吗?
示例数据(不正确)
╔════════════╦═════════╦═════════════╗
║ Revenue ║ Budget ║ ActualMonth ║
╠════════════╬═════════╬═════════════╣
║ 6.9172 ║ 3.5046 ║ Jan ║
║ 7.3273 ║ 3.7383 ║ Feb ║
║ 7.3273 ║ 3.9719 ║ Mar ║
║ 7.2726 ║ 4.2056 ║ Apr ║
║ 7.2595 ║ 6.7757 ║ May ║
║ 7.2726 ║ 6.7757 ║ Jun ║
║ 0.41 ║ 0.00 ║ Jul ║
║ 0.41 ║ 0.00 ║ Aug ║
║ 0.41 ║ 0.00 ║ Sep ║
║ 0.41 ║ 0.00 ║ Oct ║
║ 7.4696 ║ 0.00 ║ Nov ║
║ 7.4696 ║ 0.00 ║ Dec ║
║ 0.00 ║ 9.3457 ║ Sep ║
║ 0.00 ║ 16.3551 ║ Dec ║
║ 0.00 ║ 6.3084 ║ Jul ║
║ 0.00 ║ 14.0186 ║ Oct ║
║ 0.00 ║ 16.3551 ║ Nov ║
║ 0.00 ║ 6.1915 ║ Aug ║
╚════════════╩═════════╩═════════════╝
正确的数据
╔════════════╦═════════╦═════════════╗
║ Revenue ║ Budget ║ ActualMonth ║
╠════════════╬═════════╬═════════════╣
║ 6.9172 ║ 3.5046 ║ Jan ║
║ 7.3273 ║ 3.7383 ║ Feb ║
║ 7.3273 ║ 3.9719 ║ Mar ║
║ 7.2726 ║ 4.2056 ║ Apr ║
║ 7.2595 ║ 6.7757 ║ May ║
║ 7.2726 ║ 6.7757 ║ Jun ║
║ 0.41 ║ 6.3084 ║ Jul ║
║ 0.41 ║ 6.1915 ║ Aug ║
║ 0.41 ║ 9.3457 ║ Sep ║
║ 0.41 ║ 14.0186 ║ Oct ║
║ 7.4696 ║ 16.3551 ║ Nov ║
║ 7.4696 ║ 16.3551 ║ Dec ║
╚════════════╩═════════╩═════════════╝
A outer join B outer join C
和A outer join C outer join B
是一样的。实际上,它甚至和A outer join (B outer join C)
一样。我不明白你的问题(注意:这适用于B和C都连接到A的情况)。 - RichardTheKiwiWHERE Revenue>0
- TechDo