答案 0 :(得分:0)
我不知道你的两个表名是什么,但这应该有效。您在加入idMaterial
后尝试在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
答案 1 :(得分:0)
我认为你需要这个
SELECT SUM(hr) FROM
(
Select sum(qty) as hr FROM table1
UNION ALL
Select sum(qty) as hr FROM table2
)a