Monthly Growth

SQL practice problem 60 of 67 · Boss Fights · Hard · 50 coins for your first accepted solve

Revenue is the sum of qty × price over all purchases.

For every month that has purchases, return month (text like 2026-10), revenue, and pct_change — the percentage change versus the previous month that has purchases, rounded to 1 decimal. The first month's pct_change is NULL.

Sort by month.

Schema

CREATE TABLE players (
  id         INT PRIMARY KEY,
  name       TEXT NOT NULL,
  country    TEXT,            -- NULL = unknown
  level      INT NOT NULL,
  joined_on  DATE NOT NULL,
  mentor_id  INT              -- another player's id, or NULL
);

CREATE TABLE items (
  id        INT PRIMARY KEY,
  name      TEXT NOT NULL,
  category  TEXT NOT NULL,
  price     NUMERIC(8,2) NOT NULL
);

CREATE TABLE purchases (
  id         INT PRIMARY KEY,
  player_id  INT NOT NULL REFERENCES players(id),
  item_id    INT NOT NULL REFERENCES items(id),
  qty        INT NOT NULL,
  bought_at  DATE NOT NULL
);

Write your query in the browser, run it on the sample data, then submit it against hidden test data.

Previous: Mentor Lineage · Next: Hot Streak · All problems