A logistics coordinator at Brightlane is distributing a shipment of 1,000 units equally across 3 warehouses. Any leftover units will be handled in a separate process.
Write a query to return each warehouse's whole-unit share in a single column named units_per_warehouse. The leftover units are out of scope here.
Output:
- A single row with one column,
units_per_warehouse, expressed as a whole number.
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
1000 / 3 AS units_per_warehouse The shape
Both operands are integers, so SQL performs integer division and truncates the fractional part automatically. The truncation is the point — the warehouses need whole units, and 1000 / 3 returns exactly that.
Clause by clause
SELECT 1000 / 3evaluates the division once and returns333. Both operands are integer literals, so PostgreSQL applies integer division: the mathematical quotient is333.333..., but the fractional part is dropped before the result lands. The.333...is gone the moment the operator evaluates; there's no second chance to recover it.AS units_per_warehouselabels the column in the unit the coordinator is working in. The result reads as a count of whole units per warehouse, which is exactly what the distribution plan needs.
Why this and not 1000::numeric / 3
Casting either operand to numeric would force decimal division. 1000::numeric / 3 returns 333.333... and preserves the fractional unit. That's the wrong shape for this problem — the prompt explicitly says leftover units are handled in a separate process, so the answer is the truncated whole-number share, not the exact mathematical quotient.
Integer division as truncation is the right tool any time the answer is naturally a count: rows per page, items per crate, units per warehouse. The behaviour is a feature here, not a trap. The trap shape appears when the calculation needs to preserve cents or fractional units and the integer operands silently drop them — see the next problem for that case.
You practiced relying on integer division to get a truncated whole-number result. 1000 / 3 evaluates to 333 (not 333.33...) because both operands are integers — the recurring shape any time the answer is naturally a count of whole units.