← SQL workplace practice

Procurement tradeoffs and award evidence · Original fictional data · Free files and full answers

Allocate a divisible demand by cheapest capacity first

For A demand20, ignore MOQ and fixed freight for this explicitly divisible allocation. Order bids by unit_cents,id; allocate up to capacity until20 filled. Return bid_id,award_units,goods_cents for positive awards sorted bid_id.

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 A demand20, ignore MOQ and fixed freight for this explicitly divisible allocation. Order bids by unit_cents,id; allocate up to capacity until20 filled. Return bid_id,award_units,goods_cents for positive awards sorted bid_id.
  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 bid_id, award_units, goods_cents. Sort order follows the task. Output has 3 rows; an empty CSV field means NULL.

Source data

bids

9 source rows · Download bids CSV

id INTEGERsupplier TEXTsku TEXTunit_cents INTEGERshipping INTEGERcapacity INTEGERmoq INTEGERlead_days INTEGERexpires INTEGERrisk_low INTEGERrisk_high INTEGER
1AlphaA1002001223200100
2BetaA9035084525100400
3GammaA110020121000
4AlphaB2002001024200100
5BetaB18035062625100400
6GammaB230012121000
7DeltaA8050055730300900
8DeltaB17050084730300900
9EpsilonA50250101825100300

kit

2 source rows · Download kit CSV

sku TEXTunits INTEGER
A6
B3

amendments

3 source rows · Download amendments CSV

line TEXTold_units INTEGERnew_units INTEGERunit_cents INTEGER
L158100
L240200
L303150
Field dictionary and schema
bids:
  id INTEGER — Stable source record identifier; not a row position.
  supplier TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  sku TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  unit_cents INTEGER — Exact integer monetary cents; no implicit currency conversion.
  shipping INTEGER — Fixed supplier order freight in cents.
  capacity INTEGER — Maximum quantity this bid can supply.
  moq INTEGER — Minimum nonzero order quantity.
  lead_days INTEGER — Elapsed delivery lead time in days.
  expires INTEGER — Expiry boundary; the goal declares whether equality is eligible.
  risk_low INTEGER — Lower supplier-level risk allowance in cents.
  risk_high INTEGER — Upper supplier-level risk allowance in cents.

kit:
  sku TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  units INTEGER — Physical unit quantity, not a monetary amount.

amendments:
  line TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  old_units INTEGER — Exact integer business measurement. Its specific business rule and eligibility are declared in the task.
  new_units INTEGER — Exact integer business measurement. Its specific business rule and eligibility are declared in the task.
  unit_cents INTEGER — Exact integer monetary cents; no implicit currency conversion.

Download complete SQLite setup

A method you can reuse

  1. For A demand20, ignore MOQ and fixed freight for this explicitly divisible allocation. Order bids by unit_cents,id; allocate up to capacity until20 filled. Return bid_id,award_units,goods_cents for positive awards sorted bid_id.
  2. For the first output record, bid_id = 2; award_units = 5; goods_cents = 450.
  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

Assigning all demand to the cheapest supplier ignores that supplier’s hard capacity limit.

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
WITH x AS (SELECT *,SUM(capacity) OVER(ORDER BY unit_cents,id)-capacity prior FROM bids WHERE sku='A') SELECT id bid_id,MIN(capacity,MAX(0,20-prior)) award_units,MIN(capacity,MAX(0,20-prior))*unit_cents goods_cents FROM x WHERE prior<20 ORDER BY id;
"bid_id","award_units","goods_cents"
"2","5","450"
"7","5","400"
"9","10","500"
Reference SQL · Complete expected CSV · Empty answer CSV

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