
A line chart should show a point on a day with no deliveries. Grouping shipment events alone cannot emit a calendar day for which no shipment exists. Each row is one shipment. Minutes records the measured trip and stays null until a reading arrives. An observed zero is possible for a collection at the dispatch desk. Items counts packages; paid is a separate zero-or-one billing flag.
Set up an in-memory example
The fixture uses a fresh SQLite database. Its small size allows the result to be checked by hand before the query is applied to an export with thousands of rows. The unit of observation matters here because a query can execute cleanly and still answer a different editorial or operational question.
CREATE TABLE shipments (
id INTEGER PRIMARY KEY,
route TEXT,
day TEXT,
items INTEGER,
minutes INTEGER,
paid INTEGER
);
INSERT INTO shipments VALUES
(1, 'north', '2026-11-02', 3, 18, 1),
(2, 'east', '2026-11-02', 2, 26, 1),
(3, 'north', '2026-11-03', 1, NULL, 0),
(4, 'east', '2026-11-04', 4, 26, 1),
(5, 'west', '2026-11-04', 1, 9, 0),
(6, 'north', '2026-11-06', 5, 40, 1);Inspect the selected rows
WITH RECURSIVE days(d) AS (VALUES('2026-11-02') UNION ALL SELECT date(d,'+1 day')
FROM days
WHERE d<'2026-11-06') SELECT d,count(s.id) AS trips
FROM days
LEFT JOIN shipments s ON s.day=d
GROUP BY d
ORDER BY d;| d | trips |
|---|---|
| 2026-11-02 | 2 |
| 2026-11-03 | 1 |
| 2026-11-04 | 2 |
| 2026-11-05 | 0 |
| 2026-11-06 | 1 |
Count the joined shipment ID. COUNT(*) would count the preserved calendar row on an empty day as if it were a trip.
What changes with one more record?
Append this single row to the same fixture and rerun the query. Its named fields are id = 7, route = west, day = 2026-11-06, items = 3, minutes = 0, paid = 1. Keep the other rows intact so a comparison isolates the effect of this one insert.
INSERT INTO shipments VALUES (7, 'west', '2026-11-06', 3, 0, 1);The original query returned 5 rows. After the insert it returns 5. One resulting row is ["2026-11-06", 2]. The former row ["2026-11-06", 1] no longer appears in exactly that form. A test that checks only the row count would miss this change.
Before exporting the result, document what one displayed row represents and which fields decide its order. Look for the same shape of input in an anonymized sample from the application. A query validated only against an empty development database cannot show what happens when a record is missing, repeated or tied with another record.
SQLite reference for recursive calendar · SQLite SQL syntax reference
Sources and further reading
Cover photograph: Hard disk drive platter, Samsung MP0402H by Mk2010. CC BY 4.0. Cropped and typeset for this cover. The photograph illustrates the topic.
