I have 4 tables A, B, C and D with 3 columns each
A- aa, ab, ac
B- ba, bb, bc
C- ca, cb, cc
D- da, db, dc
I need to join the 4 tables and add a new calculated column (aa + ab + ac). My query is
SELECT A.aa, A.ab, A.ac, B.ba, B.bb, B.bc, C.ca, C.cb, C.cc, D.da, D.db, D.dc,(A.aa + A.ab + A.ac) AS total
FROM A
LEFT JOIN B
ON A.aa = B.ba
LEFT JOIN C
ON A.ab = C.ca
LEFT JOIN D
ON A.aa = D.da;
The tables join fine, but the calculated column returns NULL for all rows. Where am I going wrong and is there any other way to do it?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…