CERTIFIED-DATA-ANALYST-ASSOCIATE · Question #12
A data analyst has been asked to count the number of customers in each region and has written the following query: If there is a mistake in the query, which of the following describes the mistake?
The correct answer is B. The query is missing a GROUP BY region clause. When counting customers per region, SQL requires a GROUP BY region clause to partition rows into groups before applying COUNT() - without it, the database doesn't know how to separate results by region and will throw an error or return a single aggregate across all rows. Option…
Question
A data analyst has been asked to count the number of customers in each region and has written the following query:
If there is a mistake in the query, which of the following describes the mistake?
Options
- AThe query is using count('). which will count all the customers in the customers table, no matter
- BThe query is missing a GROUP BY region clause.
- CThe query is using ORDER BY. which is not allowed in an aggregation.
- DThere are no mistakes in the query.
- EThe query is selecting region but region should only occur in the ORDER BY clause.
How the community answered
(43 responses)- A9% (4)
- B81% (35)
- C2% (1)
- D5% (2)
- E2% (1)
Explanation
When counting customers per region, SQL requires a GROUP BY region clause to partition rows into groups before applying COUNT() - without it, the database doesn't know how to separate results by region and will throw an error or return a single aggregate across all rows. Option A is wrong because COUNT(*) or COUNT(column) correctly counts rows and is not the issue here. Option C is wrong because ORDER BY is perfectly valid alongside aggregation functions. Option E is wrong because selecting region in the SELECT clause is required (and expected) when grouping by it.
Memory tip: Think of GROUP BY as the "buckets" clause - whenever you want aggregates (COUNT, SUM, AVG) broken out by a category column, that column must appear in GROUP BY. If you SELECT a non-aggregated column without GROUP BY, that's the red flag.
Community Discussion
No community discussion yet for this question.