Question & tables Return month and revenue_change versus prior month of paid revenue; first month NULL. Order by month.
30:00
Start / resume mock Question Finish and review Database schema customers(id, name, country)
orders(id, customer_id, ordered_at, amount, status)
employees(id, name, department, salary, manager_id)
events(id, user_id, event_date, event_type)
products(id, name, category, price, stock) orders.customer_id → customers.id employees.manager_id → employees.id events.user_id is a separate product-user identifier.
All data is synthetic. Dates use YYYY-MM-DD; unknown values are NULL.
Concept hint Name output grain, eligible records and date range. Clarify NULLs, cancellations, ties and zero values. Correct SQL for the wrong metric is still an incorrect answer.
Reference solution & explanation WITH m AS(SELECT strftime('%Y-%m',ordered_at) AS month,SUM(amount) AS revenue FROM orders WHERE status='paid' GROUP BY month) SELECT month,revenue-LAG(revenue) OVER(ORDER BY month) AS revenue_change FROM m ORDER BY month;Inspect intermediate results. Count rows before and after joins and check a known customer by hand. For percentages, state the denominator and use decimal division. Do not average group percentages without considering population weights.
The checker compares output columns, values and requested row order across two fixture variants. Different SQL that produces the same results is accepted. This is a learning aid, not a proof of correctness on every possible dataset.
Read the topic guide → Your SQL query Ctrl / Cmd + Enter to run Run query Check answer Stop Reset query Save draft Download SQL
Loading the SQL engine…
Queries run locally, with an eight-second execution limit and a 500-row result limit. Signed-in learners can save exercise queries to their academy account. Practice results never change course grades or certificates.
This workspace needs JavaScript and WebAssembly. You can still read the question and reference solution.