我有以下查询
Select TA.Column1 , COALESCE(TE.Column2,TA.Column2) as Mydata
from TableA TA
INNER JOIN TableB TB ON (TA.Column2 =TB.Column1)
LEFT JOIN TableC TC ON (TB.Column2 = TC.Column1)
LEFT JOIN TableD TD ON (TC.Column1 = TD.Column1)
LEFT JOIN TableE TE ON(TD.Column2 = TE.Column1)
要获得我想要的结果,我需要Join
MyData
列与另一个TableX
例如INNER JOIN TableX TX ON (TableX.Column1 = MyData)
并且在我的选择查询中有TableX.COlumn2
。
我的查询是如何将COALESCE(TE.Column2,TA.Column2) as Mydata
获取的值加入表TableX
答案 0 :(得分:0)
从表面上看,你应该能够做到这一点。 (你有没试过?)
Select TA.Column1 , COALESCE(TE.Column2,TA.Column2) as Mydata, TX.Column2
from TableA TA
INNER JOIN TableB TB ON (TA.Column2 =TB.Column1)
LEFT JOIN TableC TC ON (TB.Column2 = TC.Column1)
LEFT JOIN TableD TD ON (TC.Column1 = TD.Column1)
LEFT JOIN TableE TE ON(TD.Column2 = TE.Column1)
LEFT JOIN TableX TX ON (COALESCE(TE.Column2,TA.Column2)) = TX.Column1