Monthly Run Distance Leaders per Country for Nike Run Club
Last updated: November 29, 2026
Quick Overview
Given a runs table (run_id, member_id, started_at, distance_km, is_valid) and a members table (member_id, country), write SQL that returns, for each month and country, the top 3 members by total valid distance, with ties sharing a rank.
Nike
November 29, 20260
0
0 solved
Given a runs table (run_id, member_id, started_at, distance_km, is_valid) and a members table (member_id, country), write SQL that returns, for each month and country, the top 3 members by total valid distance, with ties sharing a rank.
A SQL screen in the style of Nike's consumer data and analytics teams, where Nike Run Club leaderboards and monthly challenges are built on activity data. The interviewer checks aggregation before ranking, the choice of ranking function, and whether you filter invalid or GPS-glitched runs.
What the Interviewer Expects
- Aggregates distance per member per month before ranking
- Filters invalid runs and joins country correctly
- Chooses DENSE_RANK or RANK deliberately and explains tie behaviour
- Truncates timestamps to month in a consistent time zone
- Orders the output readably
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How do you handle a member who changes country mid-month?
- Started_at is stored in UTC. Whose month boundary should apply?
- How would you make this incremental for a daily leaderboard refresh?
- How would you exclude implausible runs, such as 30 km in 20 minutes?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
One row per run. is_valid is false for runs flagged as GPS errors or manual entries the challenge excludes. A member has one current country. I will use month in UTC unless told otherwise, and say t...
Approach
First aggregate valid distance per (month, country, member). Then rank members within each (month, country) partition by total distance descending, and keep ranks 1 to 3. Aggregating first matters: ra...