Loading exercise…
Loading exercise…
Exercises are built for a keyboard. Read the task here, then open this page on a laptop to solve it.
Frames: ROWS BETWEEN. A frame says which rows the window uses. AVG(x) OVER (ORDER BY m ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) averages the current row and the two before it, and slides along with each row. Without a frame, an ordered window runs from the first row up to the current one, which gives a running average instead.
select month, revenue_target, sum(revenue_target) over (order by month rows between 1 preceding and current row) as two_month_target from targets where region_id = 3 order by month
Revenue jumps around from month to month. Elena Petrova wants a smoother trend line: the average of each month and the two months before it.
Return month (1 to 12), revenue and moving_avg_3m (the average revenue of that month and the two before it; January and February average the months available), both 2 decimals, completed orders only.
Loading the Brightline dataset…
Language
Full plan
SQL ✓ · Excel and Power BI also included
Cancel anytime · 14-day full refund · Secure payment by Stripe