AnalystPath

Annual Energy Output Growth by Panel Model

SQLHardSenior level~15 min

Problem

A solar operator records every meter reading from its arrays in the table `meter_readings`. Each row logs one reading: a `reading_id`, the `panel_model` that produced it, the kilowatt-hours generated (`kwh`), and the `recorded_at` timestamp.

For every panel model, compute its year-over-year growth in total energy output. For each model and each year that has readings, return: the `output_year`, the `panel_model`, the total kWh generated that year as `current_output`, the total kWh generated by the same model in the immediately preceding year as `prior_output`, and `growth_pct` — the percentage change from the prior year to the current year, computed as ((current_output - prior_output) / prior_output) * 100 rounded to 2 decimals.

When a model has no readings in the previous calendar year, `prior_output` and `growth_pct` are NULL. Order the result by `panel_model`, then by `output_year`.

Tables

Example rows — the live problem includes the full dataset.

meter_readings
reading_idpanel_modelkwhrecorded_at
11002002021-03-14 09:00:00
21001502021-08-02 11:30:00
31004002022-05-21 10:15:00

Expected output

Your answer should return 4 rows with the columns output_year, panel_model, current_output, prior_output, growth_pct.

Starter code (SQL)

SELECT *
FROM meter_readings;

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