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
November 29, 20260
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
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 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 ProblemsSample 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...