30.0k views
1 vote
If you SELECT attributes and use an aggregate function, you must GROUP BY the non-aggregate attributes.

A) True
B) False

1 Answer

6 votes

Final answer:

If you SELECT attributes and use an aggregate function, you must GROUP BY the non-aggregate attributes.

Step-by-step explanation:

True, if you use an aggregate function in a SQL SELECT statement, you must also include a GROUP BY clause for the non-aggregate attributes. This is necessary because the aggregate function performs calculations on groups of rows, and the GROUP BY clause specifies how those rows should be grouped. Without the GROUP BY clause, the result would be ambiguous.

For example, consider the following SQL statement:

SELECT category, COUNT(*) FROM products GROUP BY category;

This query will return the count of products for each category, grouping the results by the category attribute.

User Ryan Livingston
by
7.9k points

No related questions found