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?
- A.They must also be wrapped in an aggregate function.
- B.They must be explicitly included in the GROUP BY clause.Correct answer
- C.They can be any column from any table in the FROM clause without restriction.
- 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
- What is the primary purpose of the SQL HAVING clause in an aggregation query?
- Consider a table named 'employees' with columns 'department' and 'salary'. Which of the following queries correctly returns the average sal…
- How do standard SQL aggregate functions (such as COUNT, SUM, AVG) handle NULL values in their input columns?
- What will be the output of COUNT() versus COUNT(columnname) when the specified column contains several NULL values?
Practise more SQL
Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.
Start practising freeFree to start · No credit card needed