SQL Window Functions: FIRST_VALUE, LAST_VALUE, NTH_VALUE, and Positional Analytics/Delta from first value
Compare each row to the partition's first value.
Section: Derived positional patterns
Delta from first value
sql
sql
SELECT customer_id,
order_date,
amount,
amount - FIRST_VALUE(amount) OVER (
PARTITION BY customer_id
ORDER BY order_date
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS delta_from_first
FROM orders;Explanation
This shows how far each later value has drifted from the starting point.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Derived positional patterns
Compare current value to final partition value
Measure remaining distance to the last value.
Get the first value in each partition
Carry the earliest value across all rows in the partition.