Ignore cancelled orders (is_cancelled = 1). For each category compute every supplier's GMV and its share of the category's GMV: pct_of_category = 100 * supplier GMV / category GMV, ROUND to 2. Keep only the top 2 suppliers per category by GMV (ties: smaller supplier_id first). Return category, supplier_id, supplier_gmv (ROUND to 2) and pct_of_category. Order by category, supplier_gmv DESC, supplier_id.
| Column | Type |
|---|---|
| order_id | INTEGER |
| supplier_id | TEXT |
| category | TEXT |
| gmv | REAL |
| is_cancelled | BOOLEAN |
| order_id | supplier_id | category | gmv | is_cancelled |
|---|---|---|---|---|
| 1 | S10 | Sarees | 1200 | 0 |
| 2 | S11 | Sarees | 800 | 0 |
| 3 | S10 | Sarees | 300 | 0 |
| 4 | S12 | Sarees | 700 | 0 |
| 5 | S11 | Sarees | 500 | 1 |
| 6 | S20 | Kurtis | 400 | 0 |
| 7 | S21 | Kurtis | 600 | 0 |
| 8 | S20 | Kurtis | 100 | 0 |
| category | supplier_id | supplier_gmv | pct_of_category |
|---|---|---|---|
| Kurtis | S22 | 900 | 45 |
| Kurtis | S21 | 600 | 30 |
| Sarees | S10 | 1500 | 50 |
| Sarees | S11 | 800 | 26.67 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ First Day Below Reorder Point · Monthly UPI Volume Pivot by Type ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.