I need sum quantity in a different field with alias.
Image
I don't what your two table names are but this should work. You're trying to aggregate on idMaterial
after joining on idMaterial
.
SELECT A.idMaterial, C.nombre_material, A.sum_qty_entrada, B.sum_qty_salida, (A.sum_qty_entrada - B.sum_qty_salida) total
FROM (
SELECT idMaterial, SUM(qty) sum_qty_entrada FROM mesa_entrada
GROUP BY idMaterial
)
AS A
JOIN (
SELECT idMaterial, SUM(qty) sum_qty_salida FROM mesa_salida
GROUP BY idMaterial
) AS B ON
A.idMaterial = B.idMaterial
JOIN mesa_con_nombre_material AS C ON
A.idMaterial = C.idMaterial
i think that you need this
SELECT SUM(hr) FROM
(
Select sum(qty) as hr FROM table1
UNION ALL
Select sum(qty) as hr FROM table2
)a