Table: orders
+-------------+---------+ | Column Name | Type | +-------------+---------+ | order_id | int | | customer_id | int | | order_date | date | | amount | float | +-------------+---------+
order_idis the primary key.
Table: customers
+-------------+---------+ | Column Name | Type | +-------------+---------+ | customer_id | int | | region | varchar | +-------------+---------+
customer_idis the primary key.regionmay be NULL.
Join orders to customers on customer_id. Filter to orders from the last 365 days since 2026-07-01. Sum order amounts per region, treating NULL region as a separate 'Unknown' bucket. Return region and total_amount, sorted by total_amount descending.
The result format is shown below.
Example
Input:
customers table: +-------------+--------+ | customer_id | region | +-------------+--------+ | 1 | US | | 2 | EU | | 3 | APAC | +-------------+--------+ orders table: +----------+-------------+------------+--------+ | order_id | customer_id | order_date | amount | +----------+-------------+------------+--------+ | 1 | 1 | 2026-06-01 | 100 | | 2 | 1 | 2026-05-15 | 200 | | 3 | 2 | 2026-04-10 | 150 | | 4 | 3 | 2026-03-20 | 80 | +----------+-------------+------------+--------+Output:
+--------+--------------+ | region | total_amount | +--------+--------------+ | US | 300.0 | | EU | 150.0 | | APAC | 80.0 | +--------+--------------+Explanation:
Customers 1 and 2 have two and one recent orders respectively. Customer 3 has one. Summing by region and sorting by total descending gives US first.
Accepted
16/27
Acceptance Rate59.3%
Ask AI Assistant

Ask AI Assistant
Ask me anything about this coding question!
Test Cases
Input
-
Output
-
Expected
-