Broadcast the Deterministic Top Run per Pipeline
Use FIRST_VALUE to broadcast the deterministic top run_id across each pipeline.
- Window functions
- Sorting
Exercise brief
Understand the request
Benchmarking engineer Each source row needs the chosen top run identifier for later row-level comparisons.
Each source row needs the chosen top run identifier for later row-level comparisons. Use FIRST_VALUE to broadcast the deterministic top run_id across each pipeline.
Return
- Return pipeline_name, run_id, rows_loaded, and top_run_id.
- Order by pipeline_name and run_id.
Constraints
- Order by rows_loaded DESC and run_id.
- Declare the full-partition ROWS frame explicitly.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
pipeline_runs
pipeline_nameTEXTrun_idINTEGERrows_loadedINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
FIRST_VALUE returns a row value, not an aggregate maximum.
Hint 2
A stable key determines which peer supplies the identifier.
Hint 3
Use a full ROWS frame to make the intended partition scope explicit.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT pipeline_name, run_id, rows_loaded, FIRST_VALUE(run_id) OVER (PARTITION BY pipeline_name ORDER BY rows_loaded DESC, run_id ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS top_run_id FROM pipeline_runs ORDER BY pipeline_name, run_id;Why this works
FIRST_VALUE broadcasts an attribute from the first ordered row. The tie-breaker selects one peer deterministically and the explicit frame documents scope.
Success check
Every row in a pipeline carries the same deterministic top_run_id.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| pipeline_name | run_id | rows_loaded | top_run_id |
|---|---|---|---|
| billing_rollup | 301 | 1500 | 301 |
| billing_rollup | 302 | 1500 | 301 |
| billing_rollup | 303 | 1300 | 301 |
| billing_rollup | 304 | 1100 | 301 |
| customer_sync | 201 | 850 | 201 |
| customer_sync | 202 | 850 | 201 |
| customer_sync | 203 | 850 | 201 |
| customer_sync | 204 | 650 | 201 |
| ingest_orders | 101 | 1000 | 102 |
| ingest_orders | 102 | 1200 | 102 |
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.