Real-world recipes · Any daily metric

Rolling 7-day average

In Excel, you'd reach for
fx=AVERAGE(B2:B8) dragged down a column

Daily numbers jump around. A 7-day rolling average smooths them so the trend shows. In Excel you'd drag =AVERAGE(B2:B8) down the sheet so the window slides.

SQL does the sliding with a window function: AVG(x) OVER (ORDER BY day ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) means "average this row and the 6 before it".

Try itEdit the query, then Run
daysignupsrolling_7d_avg
2026-01-0122
2026-01-0211.5
2026-01-0511.33
2026-01-0611.25
2026-01-0721.4
2026-01-0811.33
2026-01-1021.43
2026-01-1111.29
2026-01-1231.57
2026-01-1321.71

Showing 10 of 157 rows. Press Run to see them all.

Days with zero signups are missing from daily here, so the window is "the last 7 rows that have data". For an exact calendar window, build a list of every day first (like the month list in the MRR recipe) and LEFT JOIN onto it.

Your turn

Running total of signups: for each signup_date, show daily signups and total_so_far, in date order.

This page on one card

Rolling 7-day average: the Excel way (=AVERAGE(B2:B8) dragged down a column) and the SQL query, side by side
Rolling 7-day average, on one card: the Excel way and the SQL. Download · Save to Pinterest
The practice data (7 tables)

See every column and sample rows