Count operational carrier handoffs within split orders
Original fictional practice · CC BY 4.0 · 2026-11-11

TASK
For each order return order_id,carrier_count,cross_carrier as1 when more than one distinct carrier is involved. Sort order_id. Count the planned package routing regardless of delivery status.

OUTPUT
order_id, carrier_count, cross_carrier

RULES
For each order return order_id,carrier_count,cross_carrier as1 when more than one distinct carrier is involved. Sort order_id. Count the planned package routing regardless of delivery status.
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
packages:
  id INTEGER — Stable source record identifier; not a row position.
  order_id INTEGER — Foreign business-record identifier; match to the named source key.
  planned_day INTEGER — Day index or ISO date as declared in this task; preserve its source representation.
  delivered_day INTEGER — Day index or ISO date as declared in this task; preserve its source representation.
  units INTEGER — Physical unit quantity, not a monetary amount.
  required_units INTEGER — Exact integer business measurement. Its specific business rule and eligibility are declared in the task.
  carrier TEXT — Literal business key or category label. Match exactly and retain NULL where present.

attempts:
  id INTEGER — Stable source record identifier; not a row position.
  package_id INTEGER — Foreign business-record identifier; match to the named source key.
  minute INTEGER — Elapsed UTC minute from the fictional scenario origin.
  result TEXT — Literal business key or category label. Match exactly and retain NULL where present.

stops:
  route TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  seq INTEGER — Declared event or route sequence, ascending within its owner.
  arrive INTEGER — Exact integer business measurement. Its specific business rule and eligibility are declared in the task.
  depart INTEGER — Exact integer business measurement. Its specific business rule and eligibility are declared in the task.
  load_delta INTEGER — Exact integer business measurement. Its specific business rule and eligibility are declared in the task.
  kind TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  pair_id TEXT — Foreign business-record identifier; match to the named source key.

proofs:
  package_id INTEGER — Foreign business-record identifier; match to the named source key.
  kind TEXT — Literal business key or category label. Match exactly and retain NULL where present.

METHOD
For each order return order_id,carrier_count,cross_carrier as1 when more than one distinct carrier is involved. Sort order_id. Count the planned package routing regardless of delivery status.
For the first output record, order_id = 1; carrier_count = 2; cross_carrier = 1.
Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.

COMMON WRONG TURN
Several packages with the same carrier do not create a cross-carrier handoff.

RESULT CHECK
For the first output record, order_id = 1; carrier_count = 2; cross_carrier = 1.

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.
