SQL LEAD
The mirror image of LAG — reach forward to the next row's value instead of back.
What & Why
LEAD(column) pulls a value from the row immediately after the current one. Same mechanics as LAG, opposite direction.
See How It Works
BUSINESS QUESTION
Show each daily active-user value beside the next day and calculate the change that follows.
| date_day | dau | new_users | returning_users |
|---|---|---|---|
| 2024-04-01 | 1240 | 180 | 1060 |
| 2024-04-02 | 1315 | 205 | 1110 |
| 2024-04-03 | 1288 | 164 | 1124 |
| 2024-04-04 | 1392 | 221 | 1171 |
Watch LEAD read the next DAU rowStep 1 of 4
LEAD(dau) OVER (ORDER BY date_day)
| date_day | dau | next_dau | change_to_next |
|---|---|---|---|
| 2024-04-01 | 1240 | 1315 | +75 |
| 2024-04-02 | 1315 | 1288 | -27 |
| 2024-04-03 | 1288 | 1392 | +104 |
| 2024-04-04 | 1392 | NULL | NULL |
April 1 looks forward to 1315.
EXAMPLE QUERY
SELECT
date_day,
dau,
LEAD(dau) OVER (ORDER BY date_day) AS next_dau,
LEAD(dau) OVER (ORDER BY date_day) - dau AS change_to_next
FROM growth.daily_active_users
ORDER BY date_day;This lesson's practice is part of Pro.
Sign up free to try it on a real business scenario