0
I have the following query:
SELECT
YEAR(NFDtEmis) AS 'Ano',
MONTH(NFDtEmis) AS 'Mes',
ItProduto AS 'Produto',
SUM(ItQtde) AS 'Quantidade total'
FROM NotasItens
INNER JOIN NotasFiscais
ON NFEmpresa = ItEmpresa
AND NFNumero = ItNfNumero
AND NFTIPO = ItTipo
INNER JOIN Tributos
ON TribEmpresa = ItEmpresa
AND TribCodigo = ItCFO
WHERE ItEmpresa = '03'
AND ItProduto = 'JKIT'
AND NFDtEmis >= '2016-04-01'
AND NFDtEmis <= '2017-07-31'
AND NFStatus = 'I'
AND NFTipo = 'S'
AND NFEmpresa = '03'
AND UPPER(RTRIM(LTRIM(TribTpCFOP))) = 'VENDA'
GROUP BY YEAR(NFDtEmis),
MONTH(NFDtEmis),
ItProduto,
ItQtde
ORDER BY YEAR(NFDtEmis), MONTH(NFDtEmis)
I wrote in the idea of bringing the total sold quantity of the product "Jkit" for each month from April/2016, but I do not know why, he is repeating the month, instead of adding everything up.
I believe I may be wrong SUM()
Upshot: