Your question is Top Customers by Closed-Won Sales. Start with the requirements and the three tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
You are given Demandbase-style CRM sales data and need to identify the top five customers by total sales. Write a PostgreSQL query that returns each customer's name and their total closed-won sales amount. Exclude opportunities that are not closed-won, and rank customers from highest to lowest total sales.
| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer name |
| segment | VARCHAR(50) | Customer segment |
| Column | Type | Description |
|---|---|---|
| opportunity_idPK | INT | Unique opportunity identifier |
| customer_id | INT | Customer tied to the opportunity |
| stage | VARCHAR(50) | Opportunity stage |
| close_date | DATE | Opportunity close date |
| Column | Type | Description |
|---|---|---|
| line_item_idPK | INT | Unique line item identifier |
| opportunity_id | INT | Opportunity tied to the line item |
| amount | DECIMAL(12,2) | Sales amount for the line item |