How can we access the previous order amount in chronological order?
LAG(column) accesses the value from the preceding row within the window without a self-join.
Period-over-period delta calculation, day-over-day growth tracking, churn detection.
SELECT
order_date,
amount,
LAG(amount) OVER (ORDER BY order_date) AS previous_amount
FROM orders;Practice typing production-grade SQL code for LAG.