> ## Content Index
> Fetch the complete content index at: https://abundance.alloconomy.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Store the interval between changes
- URL: https://abundance.alloconomy.com/alloconomy/de-interview-store-the-interval-between-changes/
- Published: 2026-11-22T05:09:12.000Z
- Updated: 2026-11-22T16:31:00.000Z
- Description: Stock is 14 units from Monday 09:00, 11 from Thursday 12:00, and 13 from Friday 08:00.
- Author: Sathya Narayanan
- Tags: Alloconomy, Data Engineering, Data Engineering Interview Field Guide, #web-only, #series-detail, #Import 2026-11-21 19:24, Less familiar fact patterns

1. [Collection · 10 seriesThe Data Engineering Interview Field Guide](https://abundance.alloconomy.com/alloconomy/data-engineering-interview-field-guide/)
2. [Series opening · 3 essaysLess familiar fact patternsSeries 3 of 10](https://abundance.alloconomy.com/alloconomy/de-interview-find-the-dispatch-that-never-happened/)
3. This essay2 of 3

Data engineering · 3 essays

Less familiar fact patterns

Complete reading path · You are in Part 2 of 3
1. Part 1[Find the dispatch that never happened](https://abundance.alloconomy.com/alloconomy/de-interview-find-the-dispatch-that-never-happened/)Twenty eligible titles were promised a Friday promotion in each of two stores.
2. Part 2**Store the interval between changes**Current essayStock is 14 units from Monday 09:00, 11 from Thursday 12:00, and 13 from Friday 08:00.
3. Part 3[Decide what a summary is allowed to forget](https://abundance.alloconomy.com/alloconomy/de-interview-decide-what-a-summary-is-allowed-to-forget/)A weekly rollup receives daily active readers, daily conversion rates, and daily shipped units.

## The interview prompt

Stock is 14 units from Monday 09:00, 11 from Thursday 12:00, and 13 from Friday 08:00\. A report asks about Thursday at exactly noon. A Friday correction later says Thursday’s change actually took effect at 10:00.

## Draw the boundary that two rows share

Write the intervals as \[Monday 09:00, Thursday 12:00), \[Thursday 12:00, Friday 08:00), and \[Friday 08:00, open). The half-open convention assigns Thursday noon to 11\. If both endpoints were inclusive, two balances would claim the same instant. Store the product and location on each interval so neighboring intervals are compared within the same stock position.

An as-of query finds the interval containing the requested instant. A duration-weighted average multiplies each quantity by the length of its overlap with the reporting window, then divides by the covered duration. Over Thursday 00:00–24:00, twelve hours at 14 and twelve hours at 11 average 12.5 units. The corrected threshold at 10:00 gives (10 × 14 + 14 × 11) / 24 = 12.25\. Both calculations assume complete coverage for a 24-hour local day.

Apply the correction to both neighboring boundaries. Moving only the second interval’s start creates a two-hour overlap. If readers must reproduce the number they saw before Friday, retain recorded-time versions or the issued report as well.

## The model behind the answer

A slow-selling title sits at 14 copies for six weeks. A daily snapshot writes 42 closing observations with the same quantity. If all inventory changes are captured, a **timespan fact** can instead record when the quantity of 14 began and when it ceased to apply. A change to 11 closes that interval and opens another.

For an as-of lookup, take the row whose start is at or before the requested instant and whose end is after it. Use an explicit convention for the open-ended interval. For a daily close, specify how events exactly at midnight fall into the business day. A unique start time alone cannot stop two intervals from overlapping.

The savings depend on how often stock changes and how people query it. A daily chart now needs a calendar expansion or interval join. I’d compare weeks of repeated rows saved against the measured cost of the most common reports. [Kimball on timespan facts](https://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/dimensional-modeling-techniques/timespan-fact-table/?ref=abundance.alloconomy.com)

## Try it in SQLite

Move the inventory boundary

Shift the change from noon to 10:00\. Inspect the quantity at the exact boundary and calculate the daily time-weighted mean.

Tables and sample dataExample query Your SQL

Run SQLStopReset example

Each run starts with fresh sample data. Use Ctrl+Enter or ⌘+Enter to run. Only your browser processes the query.

Label Measure 

## Review the two rows touched by a correction

Give the agent a migration that moves the Thursday stock change from noon to 10 a.m. Ask for the affected-row diff. Check the old interval’s end and the new interval’s start against the same instant.

**Reviewer decision.** Query one minute before 10, exactly at 10, and exactly at noon. The corrected quantities should be 14, 11 and 11, with one match apiece. Keep an original release if an analyst needs to reproduce the old answer. A blind overwrite destroys the evidence for that separate requirement.

*Further reading.* [The Data Warehouse Toolkit](https://www.amazon.com/dp/1118530802?ref=abundance.alloconomy.com), 3rd ed., on effective intervals in fact tables.

## One more question

Inventory never changes, but the sensor stops reporting for a week. Is one uninterrupted interval still justified?

Check your reasoning

That depends on the evidence model. A complete change journal can justify carrying the last known balance. A periodically polled sensor with an outage establishes only its last observation. Track observation coverage separately or end the interval when the validity promise expires.

1. [Back to the series openingLess familiar fact patternsSeries 3 of 10](https://abundance.alloconomy.com/alloconomy/de-interview-find-the-dispatch-that-never-happened/)
2. [Explore the collectionThe Data Engineering Interview Field Guide](https://abundance.alloconomy.com/alloconomy/data-engineering-interview-field-guide/)

[Previous · Find the dispatch that never happened](https://abundance.alloconomy.com/alloconomy/de-interview-find-the-dispatch-that-never-happened/) · [Next · Decide what a summary is allowed to forget](https://abundance.alloconomy.com/alloconomy/de-interview-decide-what-a-summary-is-allowed-to-forget/) · [Complete series map](https://abundance.alloconomy.com/alloconomy/data-engineering-interview-field-guide/)