A lead function returns an expression's value from a following row in an ordered window partition. It returns NULL when no following row exists. section 4.5.4
Use lead alongside window specifications to inspect nearby rows:
- Order rows by a date or other orderable column. section 4.5.4
- Define partitions when comparisons should restart for each group. section 4.5
- Choose an offset and default value where supported; otherwise replace NULL with coalesce. section 4.5.4
Compare successive energy prices
Apply lead or lag to the prices table, ordered by valid_from, to compare adjacent compensation values. Use a CTE before aggregating the resulting changes because window functions cannot be nested inside aggregate functions. section 4.5.4
