gitGood.dev
← SQL Playground

Rank Customers by Spend

HardPremium
Rank customers by total spend. Return name, total spend as total_spent, and the rank as spend_rank (1 = highest spender) using a window function so ties share a rank. Include only customers with orders. Order by spend_rank, then name.
Schema
customers (id, name, city)
orders (id, customer_id, amount, order_date)
Loading editor…
Hints