Open this example in the interactive library
Source code
CREATE TABLE queues(name TEXT PRIMARY KEY, owner TEXT);
INSERT INTO queues VALUES
('build','platform'), ('assets','design'), ('reports','platform'), ('idle','ops');
CREATE TABLE jobs(id INTEGER PRIMARY KEY, name TEXT, queue TEXT, status TEXT, ms INTEGER, created TEXT);
INSERT INTO jobs VALUES
(1,'compile-api','build','done',300,'2026-01-01 08:00'),
(2,'test-api','build','done',500,'2026-01-01 09:00'),
(3,'compile-css','assets','running',200,'2026-01-02 08:00'),
(4,'test-css','assets','queued',NULL,'2026-01-02 09:00'),
(5,'report','reports','done',100,'2026-01-03 10:00'),
(6,'publish','build','queued',NULL,'2026-01-03 11:00');
SELECT id,min(ms) OVER w AS low,max(ms) OVER w AS high FROM jobs WINDOW w AS (ORDER BY id ROWS BETWEEN 1 PRECEDING AND CURRENT ROW);
Sample output
[
{
"id": 1,
"low": 300,
"high": 300
},
{
"id": 2,
"low": 300,
"high": 500
},
{
"id": 3,
"low": 200,
"high": 500
},
{
"id": 4,
"low": 200,
"high": 200
},
{
"id": 5,
"low": 100,
"high": 100
},
{
"id": 6,
"low": 100,
"high": 100
}
]