Ranking & NTH Value SQL Topic exerciseHardVerified answerSQLite + PostgreSQL + MySQL + SQL Server live · 1 guided

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_nameTEXT
  • run_idINTEGER
  • started_atTEXT
  • rows_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_namerun_idstarted_atrows_loadedcumulative_rows_loaded
billing_rollup3012026-06-03 08:00:0015001500
billing_rollup3022026-06-03 09:00:0015003000
billing_rollup3032026-06-03 10:00:0013004300
billing_rollup3042026-06-03 11:00:0011005400
customer_sync2012026-06-03 09:30:00850850
customer_sync2022026-06-03 10:30:008501700
customer_sync2032026-06-03 11:30:008502550
customer_sync2042026-06-03 12:30:006503200
ingest_orders1012026-06-03 09:00:0010001000
ingest_orders1022026-06-03 10:00:0012002200

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

SQL Practice Online

Open the interactive workspace and practice across SQL topics.