Custom offset with LAG.
Section: LAG and LEAD basics
Look back two rows
sql
sql
SELECT month,
signups,
LAG(signups, 2) OVER (ORDER BY month) AS signups_2_months_ago
FROM monthly_signups;Explanation
Offsets larger than 1 are useful for month-over-month or quarter-over-quarter comparisons.
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 and LEAD basics