1
Hi, I can’t add up the amount of incoming products per customer per month. Can anyone help me with any tips? I’m getting the following result:
MÊS Quantidade
1 95
1 55
2 90
3 140
3 40
3 95
3 40
Correct would be:
MÊS Quantidade
1 150
2 90
3 140
3 315
Query:
SELECT MONTH(TMOV.DATASAIDA) AS MES, SUM(TITMMOV.QUANTIDADE) AS QUANTIDADE
FROM
(TPRD INNER JOIN (FCFO INNER JOIN (TMOV INNER JOIN TITMMOV ON (TMOV.IDMOV = TITMMOV.IDMOV)
AND (TMOV.CODCOLIGADA = TITMMOV.CODCOLIGADA)) ON FCFO.CODCFO = TMOV.CODCFO) ON (TPRD.IDPRD = TITMMOV.IDPRD)
AND (TPRD.CODCOLIGADA = TMOV.CODCOLIGADA)) INNER JOIN TMOVCOMPL ON (TMOV.IDMOV = TMOVCOMPL.IDMOV)
AND (TMOV.CODCOLIGADA = TMOVCOMPL.CODCOLIGADA)
WHERE TITMMOV.CODCOLIGADA Between '1' And '2' AND TMOV.CODTMV='1.1.70'
AND TMOV.CODCFO ='003582' AND CIDADECOLETA = '00051'
AND TMOV.DATASAIDA >= '2021-01-01 00:00:00'
AND TPRD.CODIGOPRD >= '04.001.0001' AND TPRD.CODIGOPRD <= '04.003.9999'
And TPRD.CODIGOPRD > '03.999.9999' AND TMOV.STATUS <> 'C'
GROUP BY TITMMOV.QUANTIDADE, TMOV.DATASAIDA
must be grouped by the same criterion as the select:
group by MONTH(TMOV.DATASAIDA)
, quantity is already grouped in theSUM
, don’t need to be in group by– Ricardo Pontual