SpinTheMic
Pro

Explain it in 60 seconds

LAG and LEAD

Data Engineering · SQL · Intermediate

What do LAG and LEAD do, and where do you use them?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • LAG reads a value from a previous row in the window.
  • LEAD reads a value from a following row.
  • Both take an offset and a default value.
  • Common for period-over-period change, gaps between events and session detection.
  • They need an ORDER BY in the OVER clause.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics