Find regions above the sales target

Group all orders by region. Return region, COUNT(*) AS order_count and SUM(amount) AS total_amount only for regions whose total_amount is strictly greater than 200. Count orders with NULL amounts too. Row order does not matter.

Difficulty: intermediate

Show hint

HAVING filters aggregate groups after GROUP BY. WHERE filters individual orders before aggregation.

Tables and sample data

Each test starts with fresh tables. Result rows may be returned in any order. Column names and column order must match.

Sample data: orders
order_id (integer)customer_id (integer)amount (numeric)status (text)region (text)
11120paidEast
22100paidEast
33200paidWest
Expected sample result
regionorder_counttotal_amount
East2220

Your solution

SQL · PostgreSQL

Results

PostgreSQL loads when you Run or Submit. Write one read-only SELECT or WITH query. Your query runs in this browser.

Back to Lesson