Ver originalselect id_albara, codi_albara, data, tipus_prov_treb,ROUND(coalesce(materials,0),2) as materials, ROUND(coalesce(stock,0),2) as stock from albaransleft join (select id_albara, sum(quantitat*multiplicatiu) as materials from comandes_albarans_families group by id_albara) T1 using (id_albara)left join (select id_albara, sum(quantitat*multiplicatiu) as stock from albarans_families group by id_albara) T2 using (id_albara)