select sum(Quant) from a1 join sum(Quant) from a2 where a1.id == a2.a1_id; ret = a1.Quant + a2.Quant;