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
Data Manipulation (SQL/Python)
Data Engineer
Nike
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

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
SQL aggregation
Window functions
DENSE_RANK
Date truncation
Data quality
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported

Related Questions