Accesses a value from a subsequent row in the partition based on the specified offset.
Same as input expressionDiperbarui: 13 Jun 2026LEAD(expression [, offset [, default_value]]) OVER ([PARTITION BY partition_expression] ORDER BY sort_expression)Column or expression whose value is retrieved
Determines the row ordering
Number of rows to look ahead (default: 1)
Default: 1
Value returned when no next row exists
1 SELECT 2 event_time, 3 event_type, 4 LEAD(event_time) OVER (ORDER BY event_time) as next_event_time, 5 TIMESTAMP_DIFF(LEAD(event_time) OVER (ORDER BY event_time), event_time, SECOND) as seconds_to_next 6 FROM `project.dataset.user_events`;
Calculates the time until the next event.
| event_time | event_type | next_event_time | seconds_to_next |
|---|---|---|---|
| 2024-01-01 10:00:00 | click | 2024-01-01 10:05:00 | 300 |
| 2024-01-01 10:05:00 | purchase | 2024-01-01 10:30:00 | 1500 |
| 2024-01-01 10:30:00 | logout | NULL | NULL |
1 SELECT 2 user_id, 3 page, 4 LEAD(page) OVER (PARTITION BY user_id ORDER BY timestamp) as next_page 5 FROM `project.dataset.pageviews`;
Shows the next page visited by the user.
Sudah paham LEAD? Latih langsung di browser
Latihan interaktif, langsung di browser.