You gotta group on everything that your are not running a function on.

I haven't looked at anything else such as the joins.