Aggregation & GROUP BY · SQL SQL

In standard SQL (ANSI SQL), if an aggregate function such as SUM() or COUNT() is used in a SELECT list, what rule applies to any other non-aggregated…

Practice question from Aggregation & GROUP BY (SQL SQL), with the correct answer and a step-by-step solution.

medium · MCQ · Q-517D63

In standard SQL (ANSI SQL), if an aggregate function such as SUM() or COUNT() is used in a SELECT list, what rule applies to any other non-aggregated columns present in that same SELECT list?

  1. A.They must also be wrapped in an aggregate function.
  2. B.They must be explicitly included in the GROUP BY clause.Correct answer
  3. C.They can be any column from any table in the FROM clause without restriction.
  4. D.They must be unique primary key columns.

Solution

According to the SQL standard, every column in the SELECT list that is not part of an aggregate function must appear in the GROUP BY clause. This ensures that the database engine knows how to group the rows corresponding to those descriptive columns.

More from Aggregation & GROUP BY

All of Aggregation & GROUP BY

Practise more SQL

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed