SQL CURRENT ROW
The frame boundary that stops (or starts) exactly at the row being processed.
What & Why
CURRENT ROW as a frame boundary means the frame includes the row being processed right now — no more, no less, at that end.
See How It Works
BUSINESS QUESTION
Growth wants a three-observation active-user average ending on each day.
| 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 |
EXAMPLE QUERY
SELECT
date_day,
dau,
ROUND(AVG(dau) OVER (ORDER BY date_day ROWS BETWEEN 2 PRECEDING AND CURRENT ROW), 2) AS trailing_avg_dau
FROM growth.daily_active_users
ORDER BY date_day;RESULT — trailing three-row DAU average
| date_day | dau | trailing_avg_dau |
|---|---|---|
| 2024-04-01 | 1240 | 1240.00 |
| 2024-04-02 | 1315 | 1277.50 |
| 2024-04-03 | 1288 | 1281.00 |
| 2024-04-04 | 1392 | 1331.67 |
CURRENT ROW makes each result stop at its own observation.
This lesson's practice is part of Pro.
Sign up free to try it on a real business scenario