Ver originalSELECT cant - SUM(campo), SUM(tabla3.suma)FROM tabla1INNER JOIN ( SELECT pk, cant - SUM(campo) AS suma FROM tabla1 GROUP BY pk, cant) tabla3 ON tabla1.pk = tabla3.pkGROUP BY cant