3504 Selected non-aggregate values must be part of the associated group.
This error occurs when an aggregate query includes a non-aggregate expression in the SELECT list, WHERE clause, ORDER BY clause, HAVING clause or WITH list that is not also exactly specified in the corresponding GROUP BY or WITH...BY clause. Note that we also return this error when ORDER BY and WITH clauses contain aggregates but the query does not.
For example, it is not legal to: SELECT State GROUP BY ZipCode; . In order for the request to be legal, it may be changed to: SELECT State GROUP BY State, ZipCode; . It is also not legal to: SELECT StateNo WITH SUM(StateNo) ORDER BY SUM(StateNo) ; A legal request is: SELECT SUM(StateNo) WITH SUM(StateNo) ORDER BY SUM(StateNo) ;
Correct the request and resubmit it.