Read a value from the previous row in the same partition.
Section: Lag, Lead, and Value Navigation
Use LAG
sql
sql
SELECT day, total_sales,
LAG(total_sales) OVER (ORDER BY day) AS previous_day_sales
FROM daily_sales;Explanation
LAG is great for deltas, trend analysis, and change detection.
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 Lag, Lead, and Value Navigation
Use FIRST_VALUE and LAST_VALUE
Return boundary values within a window frame.
Use PERCENT_RANK and CUME_DIST
Measure relative row position inside an ordered set.