Bill usage with graduated rather than volume pricing
Original fictional practice · CC BY 4.0 · 2026-11-11

TASK
For each contract sum only entitled usage. First100 units cost2 cents each; next100 cost1 cent each; remaining units cost3 cents each. Return contract_id,eligible_units,usage_charge_cents for every contract. Sort contract_id.

OUTPUT
contract_id, eligible_units, usage_charge_cents

RULES
For each contract sum only entitled usage. First100 units cost2 cents each; next100 cost1 cent each; remaining units cost3 cents each. Return contract_id,eligible_units,usage_charge_cents for every contract. Sort contract_id.
Return exactly the declared columns and order. Money uses integer cents; time and date units follow the task and field dictionary. NULL is unknown and differs from numeric zero.
These are original fictional records and exercise policies. Scenario data may be shared with related tasks, whose decisions and output contracts differ.

FIELD DICTIONARY
contracts:
  id INTEGER — Stable source record identifier; not a row position.
  start_day INTEGER — Day index or ISO date as declared in this task; preserve its source representation.
  end_day INTEGER — Day index or ISO date as declared in this task; preserve its source representation.
  seats INTEGER — Number of paid service seats.
  daily_cents INTEGER — Contracted cents per seat per day.
  trial_end INTEGER — First day of paid service, after the free trial.
  cancel_day INTEGER — Exclusive service end day if cancelled; NULL means no recorded cancellation.

usage:
  id INTEGER — Stable source record identifier; not a row position.
  contract_id INTEGER — Foreign business-record identifier; match to the named source key.
  day INTEGER — Integer day index, or ISO YYYY-MM-DD date when stored as text; the task declares cutoff semantics.
  units INTEGER — Physical unit quantity, not a monetary amount.

bills:
  id INTEGER — Stable source record identifier; not a row position.
  contract_id INTEGER — Foreign business-record identifier; match to the named source key.
  start_day INTEGER — Day index or ISO date as declared in this task; preserve its source representation.
  end_day INTEGER — Day index or ISO date as declared in this task; preserve its source representation.
  cents INTEGER — Signed integer currency cents.

METHOD
For each contract sum only entitled usage. First100 units cost2 cents each; next100 cost1 cent each; remaining units cost3 cents each. Return contract_id,eligible_units,usage_charge_cents for every contract. Sort contract_id.
For the first output record, contract_id = 1; eligible_units = 140; usage_charge_cents = 240.
Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.

COMMON WRONG TURN
Applying the highest reached unit rate to all usage is volume pricing, not a graduated band charge.

RESULT CHECK
For the first output record, contract_id = 1; eligible_units = 140; usage_charge_cents = 240.

Use setup.sql in a fresh SQLite database and run your own SELECT or WITH. reference.sql and expected.csv contain the full worked answer. All CSVs have UTF-8 headers; empty output fields represent NULL. The browser executes SQLite, not Excel formulas. No spreadsheet function engine is claimed.
