Calculate a Deterministic Running Load Total
Calculate cumulative_rows_loaded within each pipeline.
- Window functions
- Aggregation
- Sorting
Exercise brief
Understand the request
Batch monitoring engineer A timeline dashboard needs cumulative rows loaded after each run without reducing run-level detail.
A timeline dashboard needs cumulative rows loaded after each run without reducing run-level detail. Calculate cumulative_rows_loaded within each pipeline.
Return
- Return pipeline_name, run_id, started_at, rows_loaded, and cumulative_rows_loaded.
- Order by pipeline_name, started_at, and run_id.
Constraints
- Use SUM as a window function.
- Use an explicit ROWS frame and run_id tie-breaker.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
pipeline_runs
pipeline_nameTEXTrun_idINTEGERstarted_atTEXTrows_loadedINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
A windowed SUM retains every run row.
Hint 2
ROWS makes tied timestamps advance one row at a time.
Hint 3
Use UNBOUNDED PRECEDING through CURRENT ROW ordered by started_at, run_id.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT pipeline_name, run_id, started_at, rows_loaded, SUM(rows_loaded) OVER (PARTITION BY pipeline_name ORDER BY started_at, run_id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_rows_loaded FROM pipeline_runs ORDER BY pipeline_name, started_at, run_id;Why this works
The explicit physical frame gives deterministic row-by-row accumulation. A default RANGE frame could advance all timestamp peers together.
Success check
The total advances one physical run at a time and resets for each pipeline.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| pipeline_name | run_id | started_at | rows_loaded | cumulative_rows_loaded |
|---|---|---|---|---|
| billing_rollup | 301 | 2026-06-03 08:00:00 | 1500 | 1500 |
| billing_rollup | 302 | 2026-06-03 09:00:00 | 1500 | 3000 |
| billing_rollup | 303 | 2026-06-03 10:00:00 | 1300 | 4300 |
| billing_rollup | 304 | 2026-06-03 11:00:00 | 1100 | 5400 |
| customer_sync | 201 | 2026-06-03 09:30:00 | 850 | 850 |
| customer_sync | 202 | 2026-06-03 10:30:00 | 850 | 1700 |
| customer_sync | 203 | 2026-06-03 11:30:00 | 850 | 2550 |
| customer_sync | 204 | 2026-06-03 12:30:00 | 650 | 3200 |
| ingest_orders | 101 | 2026-06-03 09:00:00 | 1000 | 1000 |
| ingest_orders | 102 | 2026-06-03 10:00:00 | 1200 | 2200 |
Previewing 10 of 12 expected rows. Run the query in the editor to inspect the full result.
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
CTEs & Window Functions
Practice modular CTE pipelines, deterministic window analytics, period comparisons, deduplication, frames, and gaps-and-islands.
SQL Aggregations
Build reliable SQL metrics from aggregate functions through grain, fan-out, weighted ratios, rollups, percentiles, and approximate counts.
ORDER BY & Sorting
Practice deterministic SQL ordering with tie-breakers, custom priorities, NULL placement, expressions, joined data, aggregates, and portable top-N patterns.
Open the interactive workspace and practice across SQL topics.