Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
Inventory writes a row only when a quantity changes, so flipkart_stock_changes is sparse. Reporting needs the opposite shape: a quantity for every sku on every day in flipkart_report_days, whether or not anything happened that day.
Return one row per sku and report day, ordered by sku then report_day.
Result columns · in this order
sku | The product. |
report_day | Day of the snapshot. |
quantity | Quantity in force that day. |
source | changed if the day had its own change, carried otherwise. |
How to approach it
An equi-join can only produce rows for days that have a change. The report needs the days in between.
Sample input
| report_day |
|---|
| 2026-03-02 |
| 2026-03-03 |
| 2026-03-04 |
| 2026-03-05 |
4 rows — all rows shown.
| change_id | sku | changed_on | new_quantity |
|---|---|---|---|
| 1 | SKU-A | 2026-02-26 | 400 |
| 2 | SKU-A | 2026-03-02 | 340 |
| 3 | SKU-A | 2026-03-04 | 500 |
| 4 | SKU-B | 2026-02-28 | 120 |
| 5 | SKU-B | 2026-03-03 | 90 |
| 6 | SKU-B | 2026-03-03 | 75 |
| 7 | SKU-B | 2026-03-05 | 210 |
| 8 | SKU-C | 2026-03-03 | 60 |
| 9 | SKU-C | 2026-03-04 | 45 |
| 10 | SKU-D | 2026-02-20 | 800 |
| 11 | SKU-A | 2026-03-05 | 480 |
| 12 | SKU-C | 2026-03-05 | 30 |
| 13 | SKU-A | 2026-02-10 | 300 |
| 14 | SKU-B | 2026-02-20 | 100 |
| 15 | SKU-D | 2026-03-04 | 640 |
| 16 | SKU-D | 2026-03-05 | 610 |
16 rows — scroll inside the table to see them all.
Expected output
| sku | report_day | quantity | source |
|---|---|---|---|
| SKU-A | 2026-03-02 | 340 | changed |
| SKU-A | 2026-03-03 | 340 | carried |
| SKU-A | 2026-03-04 | 500 | changed |
| SKU-A | 2026-03-05 | 480 | changed |
| SKU-B | 2026-03-02 | 120 | carried |
| SKU-B | 2026-03-03 | 75 | changed |
| SKU-B | 2026-03-04 | 75 | carried |
| SKU-B | 2026-03-05 | 210 | changed |
| SKU-C | 2026-03-03 | 60 | changed |
| SKU-C | 2026-03-04 | 45 | changed |
| SKU-C | 2026-03-05 | 30 | changed |
| SKU-D | 2026-03-02 | 800 | carried |
| SKU-D | 2026-03-03 | 800 | carried |
| SKU-D | 2026-03-04 | 640 | changed |
| SKU-D | 2026-03-05 | 610 | changed |
15 rows — scroll inside the table to see them all.
Constraints
quantity on a given day is the most recent change on or before that day — the last known value carried forward.SKU-C's first change is on 3 March, so it has no row for 2 March.SKU-D has no change inside the window at all before 4 March, and must still be reported on 2 and 3 March at its February quantity.change_id: the higher one is the closing quantity for that day.source is 'changed' when the day had its own change and 'carried' when the value came from an earlier day.report_day.Worked example
SKU-B was set to 120 on 28 February, restated twice on 3 March — to 90, then 75 — and set to 210 on 5 March. The snapshot reads 120 carried on 2 March, 75 changed on 3 March, 75 carried on 4 March and 210 changed on 5 March.
Join on changed_on = report_day and the carried days vanish: SKU-B reports only two of the four days, SKU-D disappears from the window entirely, and 3 March comes back twice — once at 90 and once at 75 — because the same-day restatement was never resolved.
What this tests
Building a dense snapshot from a sparse change log: a spine of days joined on a range rather than on equality, with a deterministic rule for several changes in one day.
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.