Compute the median `order_value` per category WITHOUT using a MEDIAN or PERCENTILE function. Ignore NULL order values (a category whose values are all NULL does not appear). For an even number of values the median is the average of the two middle values. Return `category`, `median_value` (ROUND 2). Order by `category`.
| Column | Type |
|---|---|
| order_id | INTEGER |
| category | TEXT |
| order_value | REAL |
| order_id | category | order_value |
|---|---|---|
| 1 | Mobiles | 100 |
| 2 | Mobiles | 300 |
| 3 | Mobiles | 200 |
| 4 | Fashion | 50 |
| 5 | Fashion | 90 |
| 6 | Fashion | 70 |
| 7 | Fashion | 110 |
| 8 | Books | 15 |
| category | median_value |
|---|---|
| Books | 15 |
| Fashion | 80 |
| Mobiles | 200 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Seller Month-over-Month GMV Growth · Ordered Checkout Funnel by City ›
{{ 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.