Ver originalselect suma.*, t3.cobros, suma.total-t3.cobros as gran_total from(select t1.id_cuenta, sum(t2.importe) as total form tabla_cuenta as t1inner join tabla_emitidas as t2 on (t1.idcuenta=t2.idcuenta)group by t1.id_cuenta) as sumainner join tabla_cobros as t3 on (suma.idcuenta=t3.idcuenta)