Top Three Player Jerseys Per League Over the Last Week

Last updated: November 29, 2026

Quick Overview

Using order line and product tables, write SQL that returns the top three best-selling player jerseys by units in each league over the last seven days, excluding cancelled lines and keeping ties.

Fanatics
Data Manipulation (SQL/Python)
Data Engineer
Fanatics
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Using order line and product tables, write SQL that returns the top three best-selling player jerseys by units in each league over the last seven days, excluding cancelled lines and keeping ties.

Merchandising teams at Fanatics watch which player jerseys are surging after a trade or a big game so they can trigger reprints and homepage placement. This screen checks basic joins, filters, and a window function rank partitioned by league.

What the Interviewer Expects
  • Join order lines to products and filter to jerseys with a player
  • Exclude cancelled lines and bound the date window correctly
  • Aggregate units, not order counts
  • Rank within each league with a deliberate tie policy
  • Explain how you checked the output
Key Topics to Cover
Joins
Window functions
DENSE_RANK
Date filtering
Aggregation
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 would you change this to rank by revenue net of discounts?
  • How would you show week-over-week rank change for each player?
  • This runs every 15 minutes on billions of rows; what would you precompute?
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

order_items(order_id, product_id, quantity, unit_price, order_date, status) and products(product_id, league, player_name, product_type). A player jersey is product_type = 'JERSEY' with a non-nul...

Approach

Filter and aggregate units per (league, player), then rank inside each league with DENSE_RANK so two players tied for second both appear and the next is third. Different jersey styles (home, away, c...


Submit Your Answer
Markdown supported

Related Questions