Calculate day-over-day change.
Section: window functions
Compare to the previous row with LAG
sql
sql
SELECT
order_date,
daily_revenue,
daily_revenue - LAG(daily_revenue) OVER (ORDER BY order_date) AS delta
FROM daily_order_metrics;Explanation
`LAG` is excellent for trend analysis and time-series deltas.
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 window functions