A teaching bench records three objects passing an inventory station. The first logged amount is four units, the second is seven, and the third is three. The bench writes time only to the nearest reporting tick, and the first two records both carry the same displayed timestamp. An analyst sorts the log by time and asks for a running sum. The first line already says eleven. The second also says eleven. The analyst expects four, eleven, fourteen and suspects a duplicate. In fact, the calculation and the analyst are answering two different questions about the same records.

The question “how much is counted through this timestamp?” treats rows sharing the timestamp as peers. The question “how much is counted through this particular row in a specified ordering?” treats them as separate steps. A third question, “which object physically passed first?” might be impossible to answer from the record. A stable sort can make a table reproducible without recovering any timing information the instrument never recorded.
This article uses an invented, benign bench log and SQLite. The point is not to recommend a universal running-sum expression. It is to keep the frame, the chosen tie-break, and the measurement's actual resolution separate. Each has a direct effect on what the reader may infer from a plotted or exported running total.
Start with the record evidence
Suppose the first logged object has the stored tick 100, log sequence 1, and an increment of 4. The second has tick 100, sequence 2, and an increment of 7. The third has a later tick 101, sequence 3, and an increment of 3. The toy log deliberately makes the sequence and the clock compatible, but it does not specify how the sequence was assigned. A row can have a reliable order in a ledger without proving that it preceded another in a physical process.
Two equal timestamps establish that the exported representation does not distinguish the two values. They do not prove simultaneity. If the timestamp is a coarse rounding of a finer event time, multiple actual times can map to one displayed value. If buffering or delayed entry affects the recorded time, equality may reflect batching rather than physical proximity. A reader needs to know which clock and which stage the time describes before attaching a physical interpretation to the group.
Do not hide the ambiguity by printing more decimal places. A reporting layer can display 100.000, but that does not make the observations precise to thousandths of a tick. Nor does adding a tiny artificial offset to the second row produce new evidence. If a graph spaces tied rows along a secondary index for legibility, label that index as a plotting choice, not as improved temporal resolution.
Keep the increment distinct from the accumulated result. Four and seven are contributions at the tied tick. Eleven is their total. A report of eleven beside both records can describe a cumulative state conditional on the same tick. It does not mean that each record contributed eleven. Sum the increment column to recover fourteen, not the displayed running totals. Label the columns accordingly when a public table gives readers both.
It may help to write the intended question beside a sample output before coding. “Through tick 100” is compatible with reporting eleven on both rows. “Through the first recorded row” expects four under the stated order. “Just after the first object physically crossed” needs information about physical order, which is not provided merely by the recorded pair. Precision about the question protects against assuming the database chose the wrong answer.
Learn the default before replacing it
The SQLite window functions documentation describes the default frame for an ordered window and the peer rules. The same official documentation is also available on the www hostname. For an ordered aggregate window with no explicit frame, the default uses a range from the beginning through the current row, including its peers under the ordering terms. An aggregate such as a running sum therefore sees the same frame for tied rows in the example when the window orders only by tick.
With the fixture, the group at tick 100 contains increments four and seven. On either row, that frame includes both amounts, so the result is eleven. At tick 101, the frame includes all three and the result is fourteen. The calculation does not collapse the two records; it adds the same accumulated quantity to each result row. If a chart built from those rows shows two identical points, the repetition is a consequence of row representation, not an extra contribution.
The phrase “current row” can mislead when it appears in discussions of different frame types. For the default range frame, the boundary at the current row includes peers under the ordering in this example. For a rows frame, the boundary has a positional meaning. Write or read the whole frame rather than interpreting that short phrase in isolation. The interaction between frame type, order terms, and boundary is what determines the calculation.
The term “peer” also has scope. If an expression orders only by tick, the first two rows tie. If it orders by tick and a unique sequence, the same physical records no longer tie for that expression. A report can therefore simultaneously contain one timestamp-based calculation and one row-based calculation. The peer group belongs to the window's complete sort definition, not to a permanent quality of the records.
The default is often a good match for time-bucket reporting. Someone asking what was known through a given coarse timestamp may prefer one cumulative result per tick. If that is the report's true unit, aggregate the contributions to ticks or select a verified tick summary rather than leaving duplicate-looking cumulative values without explanation. Retaining individual source rows may still be useful in a separate trace. Choose a display consistent with the question instead of using row icons for what is fundamentally a bucket measure.
State the explicit row order you intend to use
To measure one accumulation step per logged object, choose an explicitly deterministic order and a rows frame. In the example a preserved log sequence can break ties under the coarse tick. Ordering by the tick followed by the sequence selects the first object, then the second, then the third in the stated ledger order. The current row boundary includes each one in turn. The results are four, eleven, and fourteen.
A rows frame alone does not solve an ordering tie. If the expression orders only by a timestamp shared by two rows, their relationship remains unspecified. In one observed arrangement the intermediate amount might be four. In the reverse arrangement it would be seven. The value at the end of the tied group remains eleven, but the intermediate row-level result depends on a choice the query has not made. An implementation that regularly returns one arrangement has not thereby documented that arrangement as a contract.
Select a secondary key that matches the claim. A sequence captured at entry can provide a stable registration order. A database identifier might provide a stable ordering but not describe the acquisition sequence. Alphabetical object name is appropriate for a display exercise and usually irrelevant as evidence about actual event order. Explain which key was used and what it means. “Deterministic” is a property of the calculation; “chronological” is a claim about what was measured.
Check uniqueness in the scope that matters. A sequence may restart with each shift or device. If two rows at the same tick can also have the same sequence, then those two terms do not form a total order over the partition. Add an appropriate stable identifier or preserve the tie, depending on the task. Do not silently manufacture uniqueness with an unstable position from an earlier export. A tie-break should survive ordinary reordering of stored rows.
The SQLite SELECT documentation explains that ordering of result rows remains undefined where all outer ordering expressions tie. The window order and the eventual display order are distinct. Put the desired order into the query's outer ordering too if readers are meant to see the accumulation progress row by row. An outer sort by another name does not recompute a window; it changes the order in which people see the already-computed results.
Run the small fixture both ways
The following self-contained query uses only the three constructed values. The timestamp-aware expression leaves the frame implicit for comparison. The ledger-aware expression writes out the row frame and its secondary ordering. The final display is also ordered, so the table can be read along the chosen sequence.
WITH bench(tick, log_seq, amount) AS (
VALUES (100, 1, 4), (100, 2, 7), (101, 3, 3)
)
SELECT
tick,
log_seq,
amount,
sum(amount) OVER (ORDER BY tick) AS through_tick,
sum(amount) OVER (
ORDER BY tick, log_seq
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS through_log_row
FROM bench
ORDER BY tick, log_seq;
| Tick | Log sequence | Increment | Through tick | Through log row |
|---|---|---|---|---|
| 100 | 1 | 4 | 11 | 4 |
| 100 | 2 | 7 | 11 | 11 |
| 101 | 3 | 3 | 14 | 14 |
This is a deliberately simple comparison of the two questions. In a real report, retaining both columns may be helpful for review. They should have names that communicate their different scopes. A user can then understand why the clock-tick total reaches eleven on the first displayed row while the ledger total is four. Avoid leaving both columns titled only “Running total” and relying on readers to infer the difference by looking up the code.
Notice that ordering the outer query by the sequence alone would not make the tick frame row-aware. Likewise, adding a sequence to the window order might remove the peer grouping even when the frame remains implicit. This is a reason to state the intended semantics explicitly. The goal is not merely to find a query that produces the expected three numbers. It is to give the next reader a durable description of why that query's output is meaningful.
Illustrative chart: Cumulative increments under explicit stable row order
This chart depicts only the ledger-aware column, not the default peer-aware column. The order uses stored tick and log sequence, and the unit is accumulated units. It is an invented three-row fixture, not a dataset obtained from SQLite or an official performance or measurement target. The SQLite reference documents how the expression is evaluated, not where these figures came from.
First logged object #### 4 units
Second logged object ########### 11 units
Third logged object ############## 14 units
| Logged step | Cumulative increment (units) |
|---|---|
| First logged object | 4 |
| Second logged object | 11 |
| Third logged object | 14 |
The first four units come from one record. Adding seven gives eleven, and adding three gives fourteen. The bars compare cumulative states after separate logged objects. They should not be added together; four plus eleven plus fourteen is not an inventory count. Checking the differences between consecutive values is a useful way to recover each contribution when the ledger is complete and starts at zero.
The default ordered range result would instead be eleven, eleven, fourteen on the retained source rows. Labeling that peer-aware output as “First logged object” and “Second logged object” without qualification could imply that eleven units were already present after the first. An honest alternative uses only two tick summaries, eleven through tick 100 and fourteen through tick 101, with labels that do not imply a within-tick sequence.
A graph designed to show time can use a bucket summary horizontally aligned to recorded ticks. A graph designed to show registered objects can use the displayed log sequence as its horizontal order. Superimposing a series of invented fractional times to spread the two tied rows can make the graphic look like a higher-resolution measurement than it is. If the user must see both individual amounts and the timestamp relation, a table or grouped markers can show them without manufacturing time points.
Preserve uncertainty about the physical order
Imagine that the ledger later shows an ingest sequence assigned when a recorder emptied a buffer. That sequence is real, useful, and potentially stable. It may still be unrelated to which object physically passed the bench first. The records could have been sorted by a scanner's local queue, uploaded in a batch, or inserted during later transcription. A report can say “ordered by ingestion” without claiming “ordered by physical passage.”
An independently recorded physical sequence can support a stronger claim if the evidence shows what it measures. A sensor index assigned to each crossing in a single channel may be relevant if it survives export and no other stream has been merged in an ambiguous way. A video or manual trace could in principle provide a second ordering source. This example assumes none of those extra facts. The ordinary row position and the uniqueness of a key are not enough to claim any particular one exists.
Think about the interval of ambiguity. If the log time is assigned by a well-understood clock with limited precision and each observation's assigned interval is known, the tied group marks a region where ordering is unresolved. If buffers introduce uncertain delays, even neighboring distinct ticks can require qualifying. Do not overstate what coarse rounding explains when the record is actually about entry or transmission time. The provenance of the timestamp is more important than its display format.
Where physical order matters and evidence is insufficient, there may be no single within-tick prefix to publish. If the two positive contributions are four and seven, the ambiguous first prefix is either four or seven under a simplified two-event model. The final total after both is eleven regardless. A precise uncertainty statement can communicate the range of possible intermediate states without choosing a story. If a safety or quality decision would differ between the two possibilities, consult the appropriate measurement record rather than trusting an arbitrary deterministic sort.
A harmless administrative report can still use the deterministic value four. It just needs to scope the claim to ledger order. This is not a failure to be scientific. It is an accurate description of a bookkeeping measure. A reader who wants physical time now knows to inspect another source instead of treating a digital sorting choice as evidence of a physical process.
Treat ordering as a scoped choice when records belong to batches
A single bench might restart its log sequence at the beginning of every shift. Another inventory might combine two stations that use the same sequence values. Decide whether the running total resets for a batch, station, shift, or some other defined partition. If it does, use the group boundaries consistently when calculating and displaying. An aggregate that crosses a reset boundary may answer a different question than the one printed above it.
Suppose a second bench records an amount at the same tick as the first. A time-based report of combined throughput could group their totals through the timestamp. A station-level report could compute separate running sums. Neither result inherently recovers a single combined sequence of physical events. If there is a global central registration order, use it only when that administrative sequence is the intended subject. If not, leave the relative order unresolved.
Use the right order within a partition and the right arrangement between partitions. Two locally unique sequences can coexist successfully if the query partitions by the relevant station. Showing both stations in one blended table still requires labels and outer order suitable for reading. A restarted count of one can look like a reversal or missing total if the station boundary is not visible. Make reset points explicit instead of expecting outsiders to know the table's grouping rules.
Likewise, a filter can change the population used by a running sum. A report may show the last portion of a log while cumulative totals ought to include earlier rows. Filtering the underlying window input down to the visible rows can reset those sums unintentionally. Compute the intended population first, then select the display segment when appropriate. Test which records actually belong to the frame, rather than assuming a page-level filter is merely visual.
The same issue is easy to miss near the start of a time range. A day report might use a cumulative state beginning at midnight, or a rolling inventory state that carries in the prior day's amount. The phrase “running total” does not choose between them. Keep the starting stock or reset rule explicit. In the three-row fixture the baseline is zero and the partition begins at the displayed log. That is part of the example, not an implicit truth about every inventory.
Check what happens when the record contains corrections
The tiny fixture uses positive increments so the cumulative results march upward. A real administrative log might represent returns or corrections with negative increments. A running sum can then decrease accurately. Do not force it to be visually monotone merely because a running total usually sounds like it should grow. First identify whether the recorded amount is a signed change, a fresh observation, or a corrected replacement for an earlier amount.
A replacement and an increment are different operations. If a row says that a previously reported seven should have been six, adding six to the running total may be incorrect. The project might issue a minus-one adjustment, or rebuild the trace after revising the source row. State which approach the ledger follows. A measurement tied to source record time and a correction tied to later administrative time can both be legitimate, but their running curves tell different stories.
Keep missing values and zero values distinct. A recorded zero means no numerical contribution under the stated protocol; an absent amount might mean it was not measured. A sum expression can skip missing values without proving that the missing amounts were zero. Label incomplete coverage where it affects interpretation. A practical QA check intentionally includes a missing amount and asks whether the output claims a complete tally. The answer shouldn't depend on whether the aggregate happened to return a plausible number.
Review also whether duplicates represent repeated events or repeated deliveries of one event. Two records at the same timestamp can be distinct. Repeated timestamp alone does not make one record invalid and should not drive deduplication. Use the relevant event identity and data policy. In the fixture, four and seven are two separate contributions. Removing one to repair an unexpectedly repeated cumulative value would destroy valid information rather than fix a frame.
Use an explicit unresolved status when timing or identity is being investigated. A diagram can show the result for confirmed events only and note that an ambiguous record was excluded. Another can retain a ledger total including an adjustment. Both need a clear population and meaning. A reproducible SQL calculation does not tell the reader which reporting policy the organization selected. The explanation must carry that decision.
Regression tests should distinguish ties from coincidence
Preserve a test with unequal contributions at the tied timestamp. If both amounts were the same, reversing their positions could leave the observable cumulative values unchanged. Using four and seven makes the difference between possible intermediate steps obvious. Verify the cumulative result keyed to each record, not only the list of numbers in one execution. End-of-group totals can match perfectly while an unspecified intermediate order attaches the wrong value to a row.
Insert or present the inputs in a different order and repeat the explicit ordering. A sound deterministic key should produce the same associations. Do not interpret unchanged results under an under-specified query as proof of determinism. The system may choose the same internal ordering under the current plan for reasons that have nothing to do with the report. The useful test exposes the intended ordering rather than hoping to discover all possible changes in implementation.
Try an additional later tick and another tied group. This checks whether the first step behaves as expected and whether the group totals accumulate into subsequent groups. Add a fixture for each relevant reset scope. If the laboratory ledger has two shifts, include a new shift at the same displayed tick or with a restarted sequence where that is possible under the real data model. These cases show whether the update uses the actual grouping fields.
Distinguish computation checks from presentation checks. A program can compute the correct row-based values and then render the page in descending time. A reader sees a decreasing series while the underlying key associations are accurate. If the purpose is to display most recent results first, that may be acceptable, but label it. If the purpose is to show accumulation, arrange the output to support progression. A successful unit test of the SQL does not prove that the final chart communicates it.
Check the result using a small manual table. A peer-aware current group can be accumulated by summing each group's contributions, then adding the totals of earlier groups. A row-aware state can be verified by adding one contribution at a time in the stated series. The two calculations have an invariant at the final row of each complete tick group under the matching order and population. Use that invariant as one check, not as the only one. It will not reveal a mistaken order inside the group.
Different questions can justify different frame types
SQLite's document distinguishes ROWS, RANGE, and GROUPS. A rows frame works with relative row positions. A groups frame works with peer groups for the ordering expression. A range frame uses its boundary rules and can include tied rows at the current boundary. The simple fixture needs only the default range and the explicit cumulative rows frame. Describing all possible offsets is outside the example, but the distinction explains why choosing a frame type is part of defining a measure.
If an analyst asks about the most recent two ticks, their phrase may be ambiguous. It could mean the current recorded tick and the preceding observed tick, even if the clock jumped a long time between them. It could instead mean a fixed elapsed tick interval, which may contain a gap and therefore fewer observed groups. The first is a group-count question; the second is a time-distance question. Neither is necessarily implemented by taking the previous individual row. Ask about the intended empty intervals before choosing a calculation.
Using GROUPS with a frame ending at the current group can be another way to express a peer-level cumulative measure when the grouping terms represent the bucket. If the output still retains each detail row, peer rows can still share a result. A frame does not reduce the number of rows in the result by itself. If an audience needs one mark per tick, make that a separate decision of output grain. Expressing the calculation and arranging what is shown are separate jobs.
A query author might use an explicit peer-aware frame even when SQLite's default already fits the request. That can be a good documentation decision. It protects a reviewer from guessing whether the author knew the default and intended it. The explicit expression is not more correct solely because it is longer. Its value is that the reporting definition stays visible and testable when someone later changes the query's order terms.
Walk through two honest displays of the same fixture
Imagine a trainer preparing a live demonstration. The trainer wants one screen to show how much the bench log counted through each timestamp. They group by recorded tick and show eleven followed by fourteen. The table still offers access to the three input records, with the tied pair preserved. A short label says the clock resolution leaves their physical sequence unresolved. Nothing in the plot implies an intermediate physical state of four or seven.
For a separate demonstration, the trainer wants to show how ledger entries change a running account. Each entry has a stable sequence inside a tick and appears in that order. The values show four, eleven, and fourteen. The first entry is described as the first logged object, not the earliest physical crossing. The axis is labeled by logged step. Both displays use the same amounts, and their end-of-tick totals agree. The chosen terms let a reader see why the intermediate values are not required to match.
During review someone asks why the first plot jumps from zero to eleven. The trainer can point to the shared tick and explain that the plot only marks completed timestamp groups. Another person sees the same time beside both rows in the ledger and asks whether that means the objects crossed together. The trainer can show the coarse timestamp and the log sequence, and distinguish available evidence from the stronger inference. The explanation should require neither a hidden query nor faith in the graphic.
Now consider a reader who saves a cropped image of the ledger's chart. If the heading and horizontal labels travel, the figure remains an example of accumulation by registered step. If the only word that survives is “Time,” the crop can misrepresent a stable ordering as a measured clock sequence. Build the distinction into the deliverable itself, not solely into explanatory prose farther down the page. A data export needs the same care: preserve the tick, sequence, and definition of the cumulative field.
Review the labels around averages and rates
Grouped cumulative values can also cause errors in secondary calculations. Suppose someone computes the average of the cumulative states across three displayed rows. The tick-based output counts the state at tick 100 twice because there are two underlying object rows. An average across observed ticks would count that state once. Neither calculation is a rate of physical passage. Be specific about the unit that the secondary statistic summarizes before assigning it a useful name.
The same applies to dividing by time. A ledger can have two logical steps with no resolved interval between them. A rate per logged step is one possible administrative quantity. A rate per elapsed time between tied records cannot be obtained by treating the time difference as a measured zero and dividing by it. A report can compute a rate over a larger period with a documented duration if that matches the question. It cannot recover a faster clock from repeated readings.
When a plotted line has multiple points at one x coordinate, the drawing system can connect them in its own input order. That may create a vertical segment that looks like an observed instantaneous change. Explicitly choose whether to show separate points, a bucket value, or a sequence axis, and explain the choice. If the output should be one point per observed tick, enforce that grain instead of allowing the library to pick whichever tied point happens to render on top.
Preserve comparable outputs after a report is revised
A later developer might add a deterministic order to the final table because the ties looked unstable. If they only change outer ordering, the tick-based results remain eleven and eleven. That may appear to fix the issue visually without changing the calculation. If they change ordering inside the window, the results can change even though the source amounts are identical. Document which scope was altered. A change in semantics is more important than a change in presentation and merits a clearer handoff.
When revising existing reports, name which published measures would change and why. A reader may have an archived tick summary and a new ledger chart. Comparing old and new intermediate points directly could suggest an inventory adjustment when just the frame changed. Preserve enough context for that comparison to be fair. The data may agree completely while the chosen index and frame represent different states.
Record the assumptions that make a cross-check valid. In this fixture the order includes the tick first and a unique sequence second, and both measures use the same partition and all the same input rows. A row-aware cumulative value at the final row of each tick therefore matches the tick total. If a later report sorts by something that no longer keeps ticks together inside the window, that cross-check is no longer appropriate. Write the invariant with its conditions instead of keeping a bare expected value.
Give the next analyst a short, reproducible contract
Review a transfer between two independently useful logs
Consider that one system captures the moment an object is sensed and another records the moment its submission is accepted. The two systems need not make identical ordering statements. A sensor record can be useful for studying interactions at the bench. A receipt record can be useful for reconstructing the ledger that a clerk saw. Carry a clearly labeled time column for each where both are available, and preserve their provenance through exports. Calling them both simply “time” can make the next analyst choose whichever sorts more neatly.
For a cross-check, join the records by an appropriate shared identity rather than by the timestamp alone. Two observations can share a tick, so matching every row with every other row at that tick would invent associations. A shared event key can identify a supported correspondence if the systems actually produce one. If no such link can be established, compare only aggregates or report the correspondence as unresolved. A finished looking grid is not an acceptable replacement for evidence of how records match.
Where a log is built from a handful of coarse records, compare the event order that is physically possible under the measurement model rather than writing a single path by convention. With both positive increments inside one indistinguishable tick, both internal orders end at eleven from a zero baseline. Only the intermediate state differs. With later corrections or negative movements, the largest temporary state can also differ. Do not report a peak that depends on an arbitrary tie-break as an observed physical peak unless an independent sequence supports that claim.
If a reader needs a transition before an accounting threshold, state precisely which transition is known. “The group total reaches eleven at tick 100” can be true even when it is unknown which tied event reached or crossed the threshold. Under the ledger order, the second record raises the running sum from four to eleven. Under another physically possible order it might rise from seven to eleven. The final amount agrees, but the amount and identity of the preceding intermediate step should not be narrated as a measured sequence.
Finally, preserve the distinction in a test data set small enough to inspect by hand. Include a known registration sequence and a timestamp pair, label the sequence as registration, and create an expected end-of-group result. The reviewer can then confirm both calculations without needing a claim about physical precedence. A robust fixture proves the statistic you intended rather than rewarding a database for generating one plausible story.
Write down the tested meaning
Label tied group summaries explicitly on the output so that a person reading one extracted row does not mistake a whole-group statement for an individual increment.
Include the measurement unit, stored time resolution and provenance, relevant partition, frame and ordering, and the result's display grain. Name what the tie-break means and what it does not establish. Then give one explicit tied example with a pass result. “Tick 100 has two distinct contributions, four and seven; both show eleven through tick, while the ordered ledger shows four then eleven” is a good fixture note because it proves which distinction was intended.
Review an export with the public terms still visible. A field called through_tick can be accompanied by a plain-language definition. A field called through_log_row can give the order used. Avoid guessing that every user recognizes an implementation-specific term such as peer. A one-line explanation that equal stored times group together may be sufficient if the exact ordering is available elsewhere. Retain the source increments where readers need to verify the running sum.
Finally, distinguish repeatability from evidence. A deterministic order makes the computed row-level state stable. A peer-aware total makes an end-of-tick summary natural. Neither choice creates a measured physical order among observations recorded at the same coarse tick. Choose the relevant calculation, test it under a tie, and label the answer so readers know which question it actually answers.