Compute relative change versus previous row.
Section: Time-series patterns
Day-over-day percent change
sql
sql
SELECT day,
revenue,
ROUND(
100.0 * (revenue - LAG(revenue) OVER (ORDER BY day))
/ NULLIF(LAG(revenue) OVER (ORDER BY day), 0),
2
) AS pct_change
FROM daily_revenue;Explanation
Use `NULLIF` to avoid division by zero.
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 Time-series patterns