AnalystPath

7-Day vs 28-Day Rolling Avg Divergence

SQLMediumMid level~15 min

Problem

**[Classic — forecasting]**

Compare a short-window vs long-window trend by computing both the 7-day and
28-day rolling averages, and the **divergence** (7d - 28d).

A positive divergence often signals an accelerating trend.

Return the latest 3 dates with `metric_date`, `avg_7d`, `avg_28d`, `divergence`
(all rounded to 2 dp), ordered by date descending.

Tables

Example rows — the live problem includes the full dataset.

daily_metrics
metric_datevalue

Expected output

Your answer should return 3 rows with the columns metric_date, avg_7d, avg_28d, divergence.

Starter code (SQL)

SELECT *
FROM daily_metrics;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions