Compute the 90th percentile of daily store sales per region using the NEAREST-RANK method and without percentile functions: sort the region's non-NULL `sales` values ascending; the p90 is the value at position CEIL(0.9 * n), where n is the number of non-NULL values. Return `region`, `sales_days` (n), `p90_sales` (ROUND 2). Regions with no non-NULL sales are excluded. Order by `region`.
| Column | Type |
|---|---|
| store_id | INTEGER |
| region | TEXT |
| sales_date | DATE |
| sales | REAL |
| store_id | region | sales_date | sales |
|---|---|---|---|
| 1 | North | 2026-09-01 | 100 |
| 1 | North | 2026-09-02 | 140 |
| 2 | North | 2026-09-01 | 90 |
| 2 | North | 2026-09-02 | 300 |
| 3 | North | 2026-09-01 | 120 |
| 4 | South | 2026-09-01 | 70 |
| 4 | South | 2026-09-02 | 75 |
| 5 | South | 2026-09-01 | 50 |
| region | sales_days | p90_sales |
|---|---|---|
| North | 5 | 300 |
| South | 6 | 80 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Latest Inventory Snapshot per Store · Monthly Active Subscriptions and MRR ›
{{ 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.