AnalystPath

Three-Day Rolling Average of Solar Output

SQLMediumMid level~15 min

Problem

Table: `panel_output`

| Column Name | Type |
|---|---|
| panel_id | int |
| kwh | int |
| output_date | date |

Each row is the energy a solar panel produced on one day. A panel records at most one row per day.

For each panel, compute the rolling average of `kwh` over the current day and the two days before it, **rounded to 2 decimals**. Only output a value when all three days are consecutive calendar days (no gap). Return `panel_id`, `output_date`, and the average aliased as `avg_3day`. Order by `panel_id`, then `output_date`.

Tables

Example rows — the live problem includes the full dataset.

panel_output
panel_idkwhoutput_date
1102024-07-01
1202024-07-02
1302024-07-03

Expected output

Your answer should return 3 rows with the columns panel_id, output_date, avg_3day.

Starter code (SQL)

SELECT *
FROM panel_output;

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