Read a value from the next row in the same partition.

Section: Lag, Lead, and Value Navigation

Use LEAD

sql
sql
SELECT subscription_id, starts_at,
       LEAD(starts_at) OVER (PARTITION BY user_id ORDER BY starts_at) AS next_start
FROM subscriptions;
Explanation

LEAD helps compare a row to the following event.

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 LAG
Read a value from the previous row in the same partition.
OpenIn sheetsqlsame section
Use FIRST_VALUE and LAST_VALUE
Return boundary values within a window frame.
OpenIn sheetsqlsame section
Assign row numbers
Number rows within an ordered partition.
OpenIn sheetsql1 tag match
Bucket rows with NTILE
Divide ordered rows into a fixed number of groups.
OpenIn sheetsql1 tag match
Rank rows
Assign ordered rankings with or without gaps.
OpenIn sheetsql1 tag match
Use PERCENT_RANK and CUME_DIST
Measure relative row position inside an ordered set.
OpenIn sheetsql1 tag match