-1
Have two queries, one in each table.
select SUM(quantidade) as total1 FROM tbmateria GROUP by codigomateria
select SUM(quantidade) as total2 FROM tbmateriaestoque GROUP by codigomateria
need to do (total2 - total1), but has to be a single query.
I tried to do so, but without success
SELECT
(SUM(tbmateria.quantidade) - SUM(tbmateriaestoque.quantidade)) as soma4,tbmateria.nomemateria
FROM tbmateria INNER JOIN tbmateriastock ON(tbmateria.codigomateria = tbmateriastock.codigomateria)
GROUP BY tbmateria.codigomateria.
see if this answers your question: https://answall.com/q/454569/57220
– Ricardo Pontual
What do you mean by "unsuccessful"? Gave error? The result was not expected?
– anonimo
the calculations are wrong. appears a very high numbers, for example: 1537406.250
– Hugo Senna