SQL 2023 · Aggregation and window functions
Compare with the previous row
Read the value of the previous row in the same ordering.
SELECT day, amount, amount - LAG(amount) OVER (ORDER BY day) AS change FROM sales;
Official SQL 2023 documentation
More aggregation and window functions commands
All aggregation and window functions commands · SQL 2023 cheatsheet