Spend Rank and Gap to the Next Customer

medium
Unit 17 · Window Functions X0/2 to milestone

For customers with orders, return name, spend, spend_rank (ROW_NUMBER by spend descending, ties by name) and gap_to_next: how much more the customer ranked just above them spent (NULL for rank 1). Sort by spend_rank.

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
query.sql · SQLite
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Spend Rank and Gap to the Next Customer · TechGradify