Statement
medium
Monthly revenue
Compute revenue by month: for every month return the sum of `total` for paid
orders (`status = 'paid'`) only.
Result columns: `month`, `revenue`.
- `month` is the first day of the month as a `date`, e.g. `2026-01-01`;
- `revenue` is the sum of `total` for that month;
- months without paid orders must not appear;
- sort by `month` ascending.
SQL · PostgreSQL
Schema
CREATE TABLE orders (
id integer PRIMARY KEY,
customer_id integer NOT NULL,
total integer NOT NULL,
status text NOT NULL,
created_at date NOT NULL
);
Data
INSERT INTO orders (id, customer_id, total, status, created_at) VALUES
(1, 1, 10000, 'paid', '2026-01-05'),
(2, 1, 5000, 'paid', '2026-01-20'),
(3, 2, 7000, 'cancelled', '2026-01-22'),
(4, 2, 12000, 'paid', '2026-02-03'),
(5, 3, 2500, 'paid', '2026-02-18'),
(6, 3, 9000, 'cancelled', '2026-03-01'),
(7, 1, 8000, 'paid', '2026-03-15'),
(8, 2, 2000, 'paid', '2026-03-28');
AI mentor
The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.
Log in and ask
Hints
1 of 3 unlocked · attempts: 0
Hint 1
Filter to paid orders first. The `status` check runs before grouping; otherwise
cancelled totals would be included in revenue.
Hint 2 — unlocks after 1 attempt
Hint 3 — unlocks after 3 attempts