you should group by all other selected items that not appear in the aggregate function, i.e. sum()
The aggregate function GROUP BY and SUM return inconsisten data?
-
17-06-2023 - |
Pergunta
I have this query that looks like okay(to me :)), but returns inconsistent data. The sum of some project return the correct data but some are not. Please help me spot the problem please.
SELECT
TRIM(`alias`),
TRIM(project),
SUM(`hours`)
FROM `dtr`
WHERE TRIM(`alias`) IN ('benjie','JM','myleen','alain_a','catzpantoja','jed','jeanie','mai','cherryfe','zeek','Jay-R','daisy','jeanie_tc')
AND `date` BETWEEN '2013-09-21' AND '2013-10-20'
GROUP BY TRIM(`project`)
ORDER BY TRIM(`alias`), TRIM(`project`);
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow