Menu
hardGrab · window

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

monthly_revenue
monthDATE
revenueNUMERIC(12,2)

Example input

monthly_revenue
↑ Read the question

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 plans

RM 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 plans

RM 25/mo · cancel anytime

Keep going

Company names are trademarks of their respective owners, used here only to describe practice material. mahir_data is not affiliated with, endorsed by, or sponsored by any company named on this site. Terms.