Aggregate results: Clarify the definition.\n“Scalar aggregates are multiple values returned from an SQL query that includes an aggregate function.”

Difficulty: Easy

Correct Answer: Incorrect

Explanation:


Introduction / Context:
Aggregates compress sets of rows into summarized results. Understanding the difference between scalar aggregates and grouped aggregates is essential for reading query plans and designing reports. This item misstates the definition of a scalar aggregate.



Given Data / Assumptions:

  • A scalar aggregate query uses aggregate functions without a GROUP BY clause.
  • Grouped aggregates use GROUP BY to produce one result per group.
  • Common aggregates: COUNT(), SUM(), AVG(), MIN(), MAX().


Concept / Approach:
A scalar aggregate returns exactly one row with one or more aggregate expressions summarizing the entire input set (for example, SELECT COUNT() FROM T;). In contrast, a grouped aggregate returns one result per group (for example, SELECT dept, COUNT() FROM T GROUP BY dept;). Therefore, calling a scalar aggregate “multiple values” is incorrect—scalar aggregates yield a single result set row (though that row can contain multiple aggregate columns).



Step-by-Step Solution:

Write a scalar aggregate: SELECT COUNT() FROM Sales; → one row, one column.Add more aggregates: SELECT COUNT(), SUM(amount) FROM Sales; → still one row, multiple columns, but a single scalar aggregate result set.Introduce grouping: SELECT region, SUM(amount) FROM Sales GROUP BY region; → multiple rows, one per region (not scalar).Conclude the statement is incorrect.


Verification / Alternative check:
Running the examples shows the row counts: scalar = 1 row; grouped = many rows.



Why Other Options Are Wrong:

  • “Correct” reverses the definition.
  • Linking correctness to GROUP BY, windowing, or isolation is irrelevant to the scalar vs. grouped distinction.


Common Pitfalls:
Confusing “one row per query” with “one column”—a scalar aggregate can include multiple aggregate columns but still returns a single row.



Final Answer:
Incorrect

More Questions from Introduction to SQL

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion