Turning Learners Into Developers
Codekilla
CODEKILLA
Medium
SQL-W05sql

7-Day Moving Average

Problem

Given `metrics(d, value)`, compute a 7-day trailing moving average column (`avg7`). For days with fewer than 7 history points, use what's available.

Input
metrics
Output
d, value, avg7
Constraints
1 ≤ rows ≤ 10^5
Sample input
see prompt
Sample output
...
Explanation
AVG(value) OVER (ORDER BY d ROWS 6 PRECEDING).
window-fnmoving-average@DataDog
Visible test cases
in: see
out: ...
Your solution — run it, use AI if stuck
sql