ASA SQL User's Guide
Summarizing, Grouping and Sorting Query Results
Understanding which queries are valid and which are not can be difficult when the query involves a GROUP BY clause. This section describes a way to think about queries with GROUP BY so that you may understand the results and the validity of queries better.
How queries with GROUP BY are executed
GROUP BY with multiple columns
WHERE clause and GROUP BY