Driver earnings rank

easySQL~15 min · 4 tests · ridelog

Ops wants a leaderboard of drivers by money earned.

A driver’s earnings are the sum of fare over their trips with status = 'completed'. Leave out drivers with no completed trips.

Rank drivers by earnings, highest first, starting at 1. Drivers with equal earnings share a rank, and the next rank skips ahead: two drivers tied at 1 are followed by rank 3. (This is “competition” ranking, like a race with a shared podium place.)

Return one row per driver:

column type meaning
driver_id integer the driver
name text the driver’s name
earnings decimal total completed fare, rounded to 2 decimals
earnings_rank integer 1 for the top earner; ties share a rank

Row order doesn’t matter.

Tables: drivers, trips.

Learn the ideaRead the lesson →
solution.sqlDuckDB · ridelog

Press ⌘ ↵ or Run to check the visible tests. Submit runs the hidden ones too. Everything runs in your browser.

⌘ ↵ to run