Top Revenue Countries
Start Timer
0:00:00
Given an orders table, write a query to find the top three countries by total revenue from completed orders placed within the last 90 days.
Rules
- Count only orders with a status of 'completed', and ignore orders whose country is NULL.
- “Within the last 90 days” means created_at on or after midnight of the date 90 days before the date of the most recent created_at in the table.
- A country’s rank is one plus the number of countries with strictly higher total revenue. Return every country with rank 3 or better, so all countries tied for third are included.
Example:
Input:
orders table
| Column | Type |
|---|---|
id |
INTEGER |
country |
VARCHAR |
status |
VARCHAR |
revenue |
FLOAT |
created_at |
DATETIME |
Output:
| Column | Type |
|---|---|
country |
VARCHAR |
total_revenue |
FLOAT |
.
.
.
.
.
.
.
.
.
Comments