LEFT JOIN ; > (; > SELECT Cust, SUM(StandsIn) As QtyIn ; > FROM StandsIn ; > GROUP BY ; > si.cust, ; > cs.customer ; > ) ; > si ON si.cust = cs.custno ;because both the si and cs alias from the group by clause are established outside the parens.
> SELECT ; > cs.custno, ; > cs.customer, ; > QtyIn As 000000, ; > QtyOut As 000000, ; > QtyIn - QtyOut As QtyDiff ; > FROM ; > customer cs ; > LEFT JOIN ; > (; > SELECT Cust, SUM(StandsIn) As QtyIn ; > FROM StandsIn ; > GROUP BY ; > si.cust, ; > cs.customer ; > ) ; > si ON si.cust = cs.custno ; > LEFT JOIN ; > (; > SELECT Cust, SUM(SerialCnt) As QtyOut ; > FROM Stands_Out ; > GROUP BY ; > so.cust, ; > cs.customer ; > ) ; > so ON so.cust = cs.custno ; > ORDER BY cs.Customer >