DataLane

12. Day-over-day revenue growth

hardProNot started~14 minWindow functionsTime series

Asked in screens shaped like: Meta, Uber, Lyft

Put yesterday’s revenue and the percent change beside each day. The first day has no prior row, and the answer must leave it NULL rather than inventing a zero.

Requirements

  • Columns: order_day, revenue, prev_revenue, pct_change
  • Only status = 'completed'
  • prev_revenue is the previous day’s revenue by order_day
  • pct_change is (revenue - prev_revenue) / prev_revenue as a percentage, rounded to 2 decimals; NULL on the first day
  • Order by order_day

Expected output

order_day, revenue, prev_revenue, pct_change

Row order is graded, so ORDER BY matters here.

SQL editor

Loading SQL engine…

Ctrl/Cmd + Enter submits

Run your query to see the result set.

Pro problem

Hard problems unlock with Pro

Easy pads stay free. Medium and hard SQL and Python problems — editor, tests, hints, and solutions — open after you upgrade to Pro or coaching.

See plansPractice free easy problems
↑↓ navigate openesc close