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

0

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
window functions
RANK
LAG
weekly aggregation
gaps handling
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 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 Problems
Sample 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
  1. Aggregate to (seller, category, week) GMV.
  2. Rank within (category, week) by GMV descending.
  3. For each (seller, category), pull the previous row's rank and week with LAG.
  4. Keep rows wh...

Submit Your Answer
Markdown supported