While building a performance dashboard, a data analyst needs to identify product categories whose combined unit sales meet or exceed 1,000 units so that only high-volume categories appear in a chart. The transactional table sales.detail stores one row per product sold and includes the columns product_id, category_id, and units_sold.
Which SQL statement will return only the qualifying categories and their total units sold without generating a syntax error?
SELECT category_id,
SUM(units_sold) AS total_units
FROM sales.detail
WHERE units_sold >= 1000
GROUP BY category_id;
SELECT category_id,
SUM(units_sold) AS total_units
FROM sales.detail
GROUP BY category_id
HAVING SUM(units_sold) >= 1000;
SELECT category_id,
SUM(units_sold) AS total_units
FROM sales.detail
WHERE SUM(units_sold) >= 1000
GROUP BY category_id;
SELECT category_id,
SUM(units_sold) AS total_units
FROM sales.detail
GROUP BY category_id
HAVING COUNT(units_sold) >= 1000;
The correct query uses the HAVING clause to filter the grouped result set after the SUM aggregation is calculated. WHERE cannot reference aggregate values; it is evaluated before grouping, so options that place SUM in the WHERE clause are invalid. The option that switches to COUNT compares the number of rows, not the total units sold, so it does not meet the business requirement. Filtering on units_sold in the WHERE clause would exclude individual rows below 1,000 units rather than categories whose aggregated total is below the threshold.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of the HAVING clause in SQL?
Open an interactive chat with Bash
Why can't the WHERE clause reference aggregate values?
Open an interactive chat with Bash
What is the difference between COUNT and SUM in SQL?
Open an interactive chat with Bash
CompTIA Data+ DA0-002 (V2)
Data Acquisition and Preparation
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99 $11.99
$11.99/mo
Billed monthly, Cancel any time.
$19.99 after promotion ends
3 Month Pass
$44.99 $26.99
$8.99/mo
One time purchase of $26.99, Does not auto-renew.
$44.99 after promotion ends
Save $18!
MOST POPULAR
Annual Pass
$119.99 $71.99
$5.99/mo
One time purchase of $71.99, Does not auto-renew.
$119.99 after promotion ends
Save $48!
BEST DEAL
Lifetime Pass
$189.99 $113.99
One time purchase, Good for life.
Save $76!
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .