Skip to content

Practice dataset

Every SQL drill, trap and task on this site runs on one small, made-up dataset: a subscription marketplace. Merchants sell subscription products to customers on weekly, monthly and annual plans. Customers subscribe through four sales channels. Two partner marketplaces, North Market and South Market, collect the money, keep a fee and pay the merchant once a month, after a delay. The merchant’s own web checkout costs a 3% card fee, and promo access is free. On top of that sits an advances program: the platform pays a merchant early, against marketplace payouts that have not arrived yet, and keeps a ledger of what the merchant owes. In an interview you will meet a different schema, but the same kinds of columns and the same questions about them.

TableRowsOne row is
merchants12A business that sells subscriptions
products20A subscription product; a merchant can have several
transactions8,294One billing period of one subscription: a purchase, a renewal or a trial
webhook_events1,285A notification from a sales channel, August–September 2026
channel_payouts173A monthly payment from a partner marketplace to a merchant
advances38An early payment to a merchant against one marketplace payout
ledger_entries104One money movement of the advances program

merchants and products call their own key id. Every other table points to them with merchant_id or product_id:

  • products.merchant_id → merchants.id
  • transactions.product_id and webhook_events.product_id → products.id
  • channel_payouts.merchant_id, advances.merchant_id and ledger_entries.merchant_id → merchants.id
  • ledger_entries.advance_id → advances.advance_id

The names differ on the two sides, so join with ON; USING needs the same name on both. A transaction reaches its merchant through products. Every page uses the same aliases: t for transactions, p for products, m for merchants.

SELECT t.transaction_id, t.plan_id, p.name AS product, m.name AS merchant
FROM transactions t
JOIN products p ON p.id = t.product_id
JOIN merchants m ON m.id = p.merchant_id
ORDER BY t.transaction_id
LIMIT 3;
transaction_idplan_idproductmerchant
t_000001prd_03.annualProduct 03Driftwood Labs
t_000002prd_08.weeklyProduct 08Brightleaf
t_000003prd_19.monthlyProduct 19Kite Works

merchants: id (mer_01 … mer_12), name (an invented business name), country, and advances_enrolled_at: when the merchant joined the advances program, or NULL if it has not. Six of the twelve merchants are enrolled.

products: id (prd_01 … prd_20), merchant_id and name (“Product 01” …). Half of the merchants have one product; the others have two or three.

One row is one billing period of one subscription. A subscription is a chain of rows: the first purchase (or a trial) and then each renewal.

ColumnMeaning
transaction_idUnique id of this transaction
original_transaction_idId of the first transaction of the chain; all renewals of one subscription share it
customer_idThe customer, for example cus_02564
product_id, plan_idThe product and its plan, for example prd_15 and prd_15.monthly
plan_periodThe plan’s length: P1W, P1M or P1Y (ISO 8601 durations)
channelThe sales channel: north_market, south_market, web or promo
is_trialA free trial: price 0, 7 days
is_trial_conversionThe first paid period right after a trial
renewal_number1 for the first transaction of a chain, then 2, 3, …
start_time, end_timeThe period is [start_time, end_time)
charged_usdWhat the customer paid (gross)
revenue_usdRevenue net of refunds: 0 if the transaction was refunded
fee_rateThe channel’s fee: 0.15 or 0.30 on a marketplace, 0.03 on the web checkout, 0 for promo
refunded_atWhen the refund happened, or NULL; a refund ends the subscription
is_testA test purchase
countryThe customer’s country

Here is the start of one chain: a trial, the first paid month and a renewal.

SELECT transaction_id, renewal_number, is_trial, is_trial_conversion,
start_time, end_time, charged_usd
FROM transactions
WHERE original_transaction_id = 't_000028'
ORDER BY renewal_number
LIMIT 3;
transaction_idrenewal_numberis_trialis_trial_conversionstart_timeend_timecharged_usd
t_0000281truefalse2025-09-03 02:06:322025-09-10 02:06:320.00
t_0000292falsetrue2025-09-10 02:06:322025-10-10 02:06:329.99
t_0000303falsefalse2025-10-10 02:06:322025-11-10 02:06:329.99

In every chain of the dataset, each period starts exactly when the previous one ends. That is why the interval is half-open: a moment belongs to one period only.

What the sales channels told the platform in August and September 2026: event_id, type (purchase, renewal, expiration, refund), customer_id, product_id, transaction_id, occurred_at (when it happened) and received_at (when it reached us).

Webhooks are delivered at least once, so the same event_id can arrive more than once. A duplicate is an exact copy; only received_at differs. The table has 1,285 rows but 1,226 distinct event ids.

What the two marketplaces actually paid each merchant: payout_id, merchant_id, channel, period_month (the first day of the sales month), amount_usd and paid_at. North Market pays about 32 days after the month ends, South Market about 14 days, so on 2026-09-30 the latest North Market payout is for July and the latest South Market payout is for August. The web checkout has no payouts here: that money reaches the merchant directly.

The table is not clean, on purpose: some payouts are missing, some amounts differ from what the sales suggest, and one payout is duplicated. Finding these is the point of the reconciliation tasks.

The advances program has two rules. An advance is at most 70% of the proceeds the merchant expects from one marketplace for one month, and it costs a 3% fee.

advances: advance_id, merchant_id, channel, period_month (the payout it is paid against), amount_usd, fee_usd, idempotency_key (merchant:channel:month, for example mer_01:north_market:2026-06-01) and created_at. Like the payouts, the advances are not clean: a few break the program’s rules, and the money tasks ask you to find them.

ledger_entries: entry_id, merchant_id, advance_id, entry_type (advance, fee or repayment), amount_usd and created_at. The ledger is append-only. Advance and fee entries are positive, repayments are negative, so what a merchant owes is SUM(amount_usd) over all their entries, for all time.

Here is the life of one advance. mer_01 expected 97.69 USD from North Market for June, so on 2 July it got 68.38 USD (70%) and owed a fee of 2.05 USD (3%). The June payout arrived on 2 August, and the repayment took both back the same morning.

SELECT entry_id, advance_id, entry_type, amount_usd, created_at
FROM ledger_entries
WHERE advance_id = 'adv_0001'
ORDER BY entry_id;
entry_idadvance_identry_typeamount_usdcreated_at
le_00001adv_0001advance68.382026-07-02 10:00:00
le_00002adv_0001fee2.052026-07-02 10:00:00
le_00003adv_0001repayment-70.432026-08-02 09:00:00

The three entries sum to 0: this advance is closed.

All timestamps are UTC and have the type TIMESTAMP. Today is 2026-09-30 00:00. Write it as a literal, TIMESTAMP '2026-09-30', never NOW() or CURRENT_DATE: the data does not move, so a query with NOW() gives a different answer every day. “The last 30 days” is [TIMESTAMP '2026-09-30' - INTERVAL '30 days', TIMESTAMP '2026-09-30'). The latest transaction starts on 2026-09-29.

A paid transaction is not a trial, not a test purchase and not promo access. All three filters, together:

SELECT COUNT(*) AS paid
FROM transactions t
WHERE NOT t.is_trial
AND NOT t.is_test
AND t.channel <> 'promo';

Of the 8,294 transactions, 7,022 are paid. Trials and promo access cost 0, so they do not change a revenue sum, but they do change a count and an average.

Three amounts answer three different questions:

  • Gross is what the customer paid: charged_usd.
  • Net is revenue after refunds: revenue_usd, which is 0 for a refunded transaction.
  • Proceeds are what the merchant keeps after the channel’s fee: revenue_usd * (1 - fee_rate).
SELECT t.channel,
COUNT(*) AS transactions,
SUM(t.charged_usd) AS gross_usd,
SUM(t.revenue_usd) AS net_usd,
ROUND(SUM(t.revenue_usd * (1 - t.fee_rate)), 2) AS proceeds_usd
FROM transactions t
WHERE NOT t.is_test
AND NOT t.is_trial
AND t.channel <> 'promo'
AND t.start_time >= TIMESTAMP '2026-08-01'
AND t.start_time < TIMESTAMP '2026-09-01'
GROUP BY t.channel
ORDER BY t.channel;
channeltransactionsgross_usdnet_usdproceeds_usd
north_market2824079.184002.233301.92
south_market1592600.412572.442133.96
web44518.56507.58492.35

Proceeds of a month are what a marketplace owes a merchant for one month (the reconciliation and advances tasks). They are counted by event, not by sale: each sale adds charged_usd * (1 - fee_rate) in the month of its start_time, and each refund subtracts the same amount in the month of its refunded_at. The table above counts by sale. By month, August gives 3134.51 for north_market and 2140.75 for south_market: refunds of earlier sales that arrive in August lower August, and an August sale refunded in September still counts in full in August and lowers September.

When a task says “revenue”, ask which of the three it means. A finance report usually wants net or proceeds; a product dashboard may want gross.

Test purchases (is_test) are purchases merchants make to try their own checkout. They look like real ones, with real prices, so they are easy to miss. In August 2026 there are 18 test purchases with 222.82 USD of gross; leaving them in makes the month look richer than it was. Exclude them from every business number.

Refunds arrive days or weeks after the purchase: for refunded transactions, the median time from the start of the period to the refund is about 11 days, the longest about 21 days. A refunded row keeps its charged_usd, gets 0 in revenue_usd and a timestamp in refunded_at. A refund also ends the subscription: from refunded_at on, the period is no longer active, and no renewal follows. Because refunds come late, the last weeks of data still look better than they will.

A free SQL editor on the same data. Run the query, then change it: add a filter, group by another column.

SQLSQL playground: the practice dataset in PostgreSQL
SELECT channel, COUNT(*) AS transactions
FROM transactions
GROUP BY channel
ORDER BY channel;

You should see four channels: north_market 4594, promo 105, south_market 2855 and web 740.

Python can query the same database through a small db module, as the Python tasks that combine SQL and Python do. Placeholders are ?, and the values are passed separately, never pasted into the SQL text. NUMERIC values come back as Decimal and timestamps as datetime. Each execute runs in its own transaction that is rolled back, so changes to the data do not stay.

PythonPython playground
import db

con = db.connect()
rows = con.execute("SELECT id, name FROM merchants WHERE country = ? ORDER BY id", ["US"]).fetchall()
print(rows[:3])

The expected output is [('mer_01', 'Pocket Quest'), ('mer_02', 'Lumen Labs'), ('mer_03', 'Driftwood Labs')]. Calling the database from Python needs WebAssembly stack switching (JSPI), which a recent Chrome or Edge has. In other browsers the rest of Python works, but a database call raises an error.

The exercises/ folder in the repository has the same data as CSV files, every interview task as a file, pytest checks and the reference solutions. SQL runs on DuckDB, which accepts the PostgreSQL syntax the tasks use; Python runs locally through uv, which installs Python, DuckDB and pytest by itself. Run uv run db.py tasks/sql/q01.sql to execute a query and uv run pytest -k q01 to check it. The folder’s README has the details.

  • Interview protocol: how to turn the columns of a new schema into questions.
  • Filters and dates: the first SQL page, with half-open ranges on this data.
  • Python and SQL: parameters and where to do the work when Python talks to a database.
  • Glossary: gross, net, proceeds, churn and the other words of this domain.

Site content: CC BY 4.0. Code: MIT. The exercises run in your browser: PostgreSQL by PGlite, Python by Pyodide.