CompTIA Data+ (DA0-002) free question 3 / 10 · Domain 2: Data acquisition and preparation
An analyst groups sales rows by department and wants to keep only the departments whose total sales exceed a target. Which clause filters on that aggregated total after the grouping?
- WHERE, which filters the input rows before a group is formed
- HAVING, which eliminates group rows by a condition on the aggregate
- ORDER BY, which sorts the output rows by the sum of sales
- SELECT DISTINCT, which removes duplicate rows from the result table
Show the answer and explanation
Answer: B
Why this is correct
The manual describes the order of processing: after the WHERE filter, the derived input table might be grouped using GROUP BY, and group rows can then be eliminated using HAVING. If only certain groups are of interest, HAVING can be used, much like a WHERE clause, to eliminate groups from the result. Expressions in HAVING can refer to grouped expressions and to aggregates such as sum(sales).
Why the other options are wrong
"WHERE, which filters the input rows before a group is formed" … WHERE is applied to individual rows before grouping, so the department totals do not exist yet when it runs.
"ORDER BY, which sorts the output rows by the sum of sales" … ORDER BY sorts the result. It does not remove departments that miss the target.
"SELECT DISTINCT, which removes duplicate rows from the result table" … DISTINCT removes duplicate rows. It does not test a department's total against a target.
Key points
Filter rows with WHERE and filter groups with HAVING. A condition on an aggregate such as a total or count belongs in HAVING.
Go to the CompTIA Data+ (DA0-002) practice app (10 free questions; purchase unlocks all questions)