AnalystPath

Solar Installer Three-Month Rolling Averages (2021)

SQLHardSenior level~15 min

Problem

Using the same solar dataset (`Installers`, `Requests`, `Bookings`), compute a forward three-month rolling average of monthly totals for 2021.

For each 2021 month, let the monthly totals be the sum of `panel_count` and the sum of `job_minutes` across bookings whose request was made that month (0 when none). Then for each month 1..10 report the average of that month's total and the next two months' totals (the current month plus the two following months).

Columns: `month`, `avg_panel_count`, `avg_job_minutes`, each rounded to 2 decimals. Months with no bookings contribute 0 to the window. Rows may be in any order.

Tables

Example rows — the live problem includes the full dataset.

Installers
installer_idonboarded_on
102020-12-10
82021-01-13
52021-02-16
Requests
request_idhousehold_idrequested_on
6752020-12-09
1542021-02-09
10632021-03-04
Bookings
request_idinstaller_idpanel_countjob_minutes
10106338
13107396
7810028

Expected output

Your answer should return 10 rows with the columns month, avg_panel_count, avg_job_minutes.

Starter code (SQL)

SELECT *
FROM Installers;

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