Previous month's revenue
Grab wants to compare each month's revenue against the one before it.
From the monthly_revenue table, return each month, its revenue, and the previous month's revenue as prev_revenue (which is NULL for the earliest month). Order the output by month.
Schema
| month | DATE |
| revenue | NUMERIC(12,2) |
Example input
Stuck? Ask the coach for a nudge that won't give the answer away, or reveal the reference solution and a short walkthrough of why it works.
The interviewer's next question
The team wants to smooth out month-to-month noise: for each month, show the average revenue over that month and the two before it (moving_avg_3mo, rounded to 2 decimal places) — but only once three months of history actually exist. Show NULL before that.
Solving follow-ups — the questions an interviewer actually asks next — unlocks with a Basic plan.
See Basic plansRM 25/mo · cancel anytime
The finance lead only cares about declines: return just the months where revenue fell versus the previous month, along with that previous month's revenue.
Solving follow-ups — the questions an interviewer actually asks next — unlocks with a Basic plan.
See Basic plansRM 25/mo · cancel anytime