← Problems14. Month-over-month revenue growthMediumSQL
00:00 / 20:00

Month-over-month revenue growth

Medium·Acceptance ·Asked at Amazon, Walmart, PayPal

Return revenue per month and the percentage change against the previous month. The first month has no previous month, so its growth is null. Months with no orders must still appear with zero revenue.

Input schema

orders order_id bigint ordered_at timestamp amount numeric status string -- 'PAID' | 'REFUNDED' | 'CANCELLED'

Example

month revenue growth_pct 2024-01 10000.00 null 2024-02 12500.00 25.00 2024-03 0.00 -100.00

Constraints

  • Only PAID orders count toward revenue
  • growth_pct rounded to two decimal places
  • Gap months between the first and last order month must be present
  • Output ordered by month ascending

Topics

window functionsaggregation

Similar problems

Community-reported interview topic. Not an official company question and no affiliation is implied.

solution.sql
Loading editor…
Draft not saved yet · Spaces 4 · UTF-8 · ⌘↵ run, ⌘⇧↵ submit
Nothing run yet

Run against the public tests, or submit to score against all of them.