Skip to main content
← Back to Code Arena
Medium Engineer SpeedRun group-by having aggregation

SQL: WHERE vs HAVING

+200 XP · 8 min · attempt 1

Problem

Table sales(region, amount) contains the rows:

    A 60
    A 70
    A 80
    B 40
    B 90
    C 55
    C 60

How many rows does this query return?

    SELECT region, SUM(amount) AS total
    FROM sales
    WHERE amount > 50
    GROUP BY region
    HAVING SUM(amount) > 200;

Enter a single integer.

Starter

-- 1. WHERE filters individual rows BEFORE grouping.
-- 2. GROUP BY groups the survivors.
-- 3. HAVING filters groups based on aggregates.

Your answer

Playing as a guest — you'll be asked for a display name on submit. Log in to keep your XP across devices.