Flag Sellers Whose Category GMV Rank Fell Week Over Week
Last updated: November 29, 2026
Quick Overview
Given an order_items table, compute each seller's weekly GMV rank within its category and return sellers who were in the top 10 the previous week and lost at least three positions this week.
Flipkart
November 29, 20260
0
0 solved
Given an order_items table, compute each seller's weekly GMV rank within its category and return sellers who were in the top 10 the previous week and lost at least three positions this week.
Flipkart's seller success and category teams watch top-seller movements to catch stockouts, pricing problems or listing issues early. SQL rounds for data engineers and analysts use this to test window functions (RANK and LAG), correct partitioning, and the subtle issue of gaps between weeks.
What the Interviewer Expects
- Aggregate GMV per seller, category and week before ranking
- Use RANK partitioned by category and week
- Use LAG partitioned by seller and category ordered by week
- Guard against comparing non-consecutive weeks
- Exclude cancelled items and explain tie handling
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 also flag top-10 sellers who had zero sales this week?
- Would you use RANK, DENSE_RANK or ROW_NUMBER here and why?
- How would you make this incremental for a daily pipeline on a very large table?
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, seller_id, category, order_ts, item_price, qty, status). GMV = price times quantity for non-cancelled items. Week starts Monday. Assume one category per item row; a seller can ...
Approach
- Aggregate to
(seller, category, week)GMV. - Rank within
(category, week)by GMV descending. - For each
(seller, category), pull the previous row's rank and week withLAG. - Keep rows wh...