
Answer-first summary for fast verification
Answer: The query is missing a GROUP BY region clause.
The query is missing a GROUP BY clause. When using aggregate functions like COUNT() alongside non-aggregated columns (region), SQL requires a GROUP BY clause to specify how to group the data for aggregation. Without GROUP BY region, the query would either return an error or count all customers across all regions as a single group, which doesn't fulfill the requirement of counting customers per region. Option B correctly identifies this fundamental SQL aggregation rule. Option A is incorrect because COUNT(*) or COUNT(customer_id) would work for counting customers. Option C is wrong as ORDER BY is allowed in aggregations. Option D is incorrect because there is a clear mistake. Option E is incorrect because selecting region is necessary for showing the breakdown by region.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
A data analyst has been asked to count the number of customers in each region and has written the following query:
SELECT
region,
COUNT(customer_id) AS customer_count
FROM customers
SELECT
region,
COUNT(customer_id) AS customer_count
FROM customers
If there is a mistake in the query, which of the following describes the mistake?

A
The query is using count(*), which will count all the customers in the customers table, no matter the region.
B
The query is missing a GROUP BY region clause.
C
The query is using ORDER BY, which is not allowed in an aggregation.
D
There are no mistakes in the query.
E
The query is selecting region, but region should only occur in the ORDER BY clause.