Question

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`);
Was it helpful?

Solution

you should group by all other selected items that not appear in the aggregate function, i.e. sum()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top