D8LooPFocus modeCODE WORKSPACE
Return buyer_id, paid_revenue, and buyer_rank for buyers whose paid-revenue rank is at most 3.
Start by naming the output grain, then build CTEs that can be inspected one at a time.
Sample input
| buyer_id | paid_orders |
|---|---|
| 2 | 540 + 110 |
| 6 | 640 |
| 3 | 120 + 95 |
| 1 | 80 |
Expected output
| buyer_id | paid_revenue | buyer_rank |
|---|---|---|
| 2 | 650 | 1 |
| 6 | 640 | 2 |
| 3 | 215 | 3 |
Constraints
State the output contract first, use readable CTE layers, return the exact columns requested by the prompt, and use deterministic ordering.
Expected skills
Interview clarification, SQL structure, edge-case handling, and final-answer narration.
Run the SQL query to inspect preview rows.