我浏览了这个问题的解决方案,遗憾的是无法得到任何帮助。在这里,我得到“列可能不是外部加入子查询”的问题。 Afaik With子句在这里不会有帮助,因为子查询在这里引用表B.PFB是问题陈述的摘录。
SELECT *
FROM ( ( A a1
JOIN A a2
ON a1.temp = a2.temp1 )
JOIN C c1
ON c1.column1 = a2.column1
AND c1.column2 = a2.column2
AND c1.column3 = a2.column3 )
LEFT JOIN C c3
ON c3.column1 = a2.column1
AND c3.column2 = a2.column2
AND c3.column3 = a2.column3
AND c3.column4 =
(SELECT MAX(c4.column4)
FROM C c4
WHERE c4.column1 = a2.column1
AND c4.column2 = a2.column2
AND c4.column3 = a2.column3
) ;
提前致谢。
答案 0 :(得分:0)
我没有意识到Oracle不支持on
子句中的子查询。在这种情况下,您可以使用分析函数轻松解决问题:
SELECT *
FROM A a1 JOIN
A a2
ON a1.temp = a2.temp1 JOIN
C c1
ON c1.column1 = a2.column1 AND
c1.column2 = a2.column2 AND
c1.column3 = a2.column3 LEFT JOIN
(SELECT c3.*,
MAX(c3.column4) OVER (PARTITION BY c3.column1, c3.column2, c3.column3) as maxcol4
FROM C c3
) c3
ON c3.column1 = a2.column1 AND
c3.column2 = a2.column2 AND
c3.column3 = a2.column3 AND
c3.column4 = c3.maxcol4;
我猜你可以在查询的其他地方使用分析函数来简化逻辑。