1-- Find total sales per active salesperson this year
2SELECT
3 salesperson_id,
4 SUM(amount) AS total
5FROM sales
6GROUP BY salesperson_id
7HAVING YEAR(sale_date) = 2024
8 AND status = 'ACTIVE';
no lines flagged
#027PracticeMedium15 min · 120 XP
HAVING Used Instead of WHERE
A query filters rows before aggregation but uses HAVING, causing a full table scan on 10 million rows.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.