Which clause lists the fields that are not summarized in the SELECT clause when using aggregate functions?

Study for the SQL Basics Test. Improve your knowledge with multiple choice questions and detailed explanations. Prepare effectively to master SQL concepts!

Multiple Choice

Which clause lists the fields that are not summarized in the SELECT clause when using aggregate functions?

Explanation:
When you use aggregate functions like SUM, AVG, or COUNT in a SELECT, any column that isn’t itself wrapped in an aggregate must be a grouping key. The clause that lists those fields is GROUP BY. It defines how rows are grouped so the aggregates are calculated within each group. For example, SELECT department, SUM(sales) FROM orders GROUP BY department demonstrates how department is not aggregated and must appear in the GROUP BY clause. If you omit GROUP BY (or include a non-aggregated column without grouping), the query can’t determine how to combine rows. Other clauses serve different roles: WHERE filters rows before grouping, HAVING filters groups after aggregation, and ORDER BY sorts the final results.

When you use aggregate functions like SUM, AVG, or COUNT in a SELECT, any column that isn’t itself wrapped in an aggregate must be a grouping key. The clause that lists those fields is GROUP BY. It defines how rows are grouped so the aggregates are calculated within each group.

For example, SELECT department, SUM(sales) FROM orders GROUP BY department demonstrates how department is not aggregated and must appear in the GROUP BY clause. If you omit GROUP BY (or include a non-aggregated column without grouping), the query can’t determine how to combine rows.

Other clauses serve different roles: WHERE filters rows before grouping, HAVING filters groups after aggregation, and ORDER BY sorts the final results.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy