← SQL workplace practice

Delivery evidence and route operations · Original fictional data · Free files and full answers

Count operational carrier handoffs within split orders

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.

Use this fixed business case to build a checked CSV and a replayable SQL handoff. No account required. Scenario datasets are shared across related exercises; each exercise has its own decision and output contract.

Your output contract

  1. 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.
  2. 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.
  3. These are original fictional records and exercise policies. Scenario data may be shared with related tasks, whose decisions and output contracts differ.

Return columns exactly as order_id, carrier_count, cross_carrier. Sort order follows the task. Output has 5 rows; an empty CSV field means NULL.

Source data

packages

7 source rows · Download packages CSV

id INTEGERorder_id INTEGERplanned_day INTEGERdelivered_day INTEGERunits INTEGERrequired_units INTEGERcarrier TEXT
113225X
213435Y
324444X
435NULL13Y
535523Y
646522X
756712Y

attempts

10 source rows · Download attempts CSV

id INTEGERpackage_id INTEGERminute INTEGERresult TEXT
11100success
22120failed
32200success
4380success
54150failed
64240failed
75160success
86200success
97300failed
107500success

stops

6 source rows · Download stops CSV

route TEXTseq INTEGERarrive INTEGERdepart INTEGERload_delta INTEGERkind TEXTpair_id TEXT
R10105pickupA
R230404pickupB
R36075-5dropA
R49095-4dropB
S105-2dropC
S220302pickupC

proofs

5 source rows · Download proofs CSV

package_id INTEGERkind TEXT
1signature
2photo
3signature
5scan
6signature
Field dictionary and schema
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.

Download complete SQLite setup

A method you can reuse

  1. 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.
  2. For the first output record, order_id = 1; carrier_count = 2; cross_carrier = 1.
  3. Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.

Watch for this wrong turn

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

Run and check in SQLite

Your SQL runs locally in the existing SQLite worker. The checker compares every column, row, type, value and row order with this fixed output. It accepts equivalent SELECT or WITH queries. Browser storage keeps your SQL on this device when available.

Complete worked SQL and expected output
SELECT order_id,COUNT(DISTINCT carrier) carrier_count,COUNT(DISTINCT carrier)>1 cross_carrier FROM packages GROUP BY order_id ORDER BY order_id;
"order_id","carrier_count","cross_carrier"
"1","2","1"
"2","1","0"
"3","1","0"
"4","1","0"
"5","1","0"
Reference SQL · Complete expected CSV · Empty answer CSV

Choose another SQL task · Original data exception cases · Larger workplace projects