Summarize sales by region

Return region and SUM(amount) AS total_amount for every region represented in orders, including a NULL region. Do not filter by status. If a region has only NULL amounts, its total_amount must be NULL. Row order does not matter.

Difficulty: beginner

Show hint

GROUP BY region creates one result row per region. SUM ignores NULL values but returns NULL when all inputs are NULL.

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)
1150paidEast
2280pendingWest
3170paidEast
Expected sample result
regiontotal_amount
East120
West80

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