N001-H1 Tier 1 · Foundations · hard

Return the precise number of boxes per crate, including the fractional portion

Part of SELECT and Column Expressions in SQL

The problem

Brightlane's warehouse operations analyst is planning load distribution across shipping crates ahead of a high-volume promotional week. There are 43 boxes to be split as evenly as possible across 8 crates, and the planning tool requires the exact decimal average — not a whole-number approximation.

Write a query to return the precise number of boxes per crate, including the fractional portion.

Output:

  • A single row with one column, boxes_per_crate, expressed as a decimal value.

Run previews · Check grades

Write a query, then run it to see results here.

Worked solution Try it yourself first
Solution query
SELECT
  43.0 / 8 AS boxes_per_crate

The shape

The decimal point on 43.0 is doing all the work. Without it, SQL treats both numbers as integers and drops the fractional part of the result entirely, which is exactly the whole-number approximation the planning tool can't use.

Clause by clause

  • SELECT 43.0 / 8 evaluates the division once and returns its single result. There's no FROM because there's no table to read from; the values come straight from the prompt as literals.
  • AS boxes_per_crate labels the output column so the result reads as a domain quantity instead of a math expression. Without the alias, PostgreSQL would label the column ?column?.

Why this and not 43 / 8

Which numbers carry a decimal point decides the type of the whole division. When both sides are integers, the result is also an integer. So 43 / 8 returns 5, and the .375 is gone before you ever see it. Writing one side with a decimal point makes that side a numeric, and SQL promotes the whole expression to numeric to match — which is why 43.0 / 8 returns 5.375000. The trailing zeroes are PostgreSQL's chosen scale for the result, not a rounding artifact.

Either side is enough. All three of these return the same value:

SELECT 43.0 / 8
SELECT 43 / 8.0
SELECT 43.0 / 8.0

What does not work is writing the division as 43 / 8 and hoping the value can be salvaged after the fact. The truncation happens during the integer division itself, the moment the expression is evaluated. By the time the result exists, the .375 is already gone.

The trap

Divide two whole numbers and SQL silently drops the decimal. There is no error, no warning, no flag in the result. The query runs, returns a number that looks plausible, and the planning tool gets the wrong load per crate. Any time the fractional part of a quotient matters, put a decimal point on at least one of the operands before the division happens.

You practiced forcing decimal division by writing one operand with a decimal point (43.0 / 8). Integer-vs-decimal division is the recurring trap whenever a quotient must preserve its fractional part.

How you actually get good at SQL

Reading explains SQL. Writing it, over and over with instant feedback, is what makes you fluent.

That's the whole SQLMaxx loop: 600+ real problems, instant AI feedback, mastery you can actually see, and spaced review that won't let you forget.

A stack of SQL practice problem cards, the top card showing an employees table.
615 problems · 66 concepts

Real problems. Not toy examples.

615 hand-built problems spanning all 66 concepts, from basic SELECTs to window functions, built on real schemas and real business questions, the kind you'll actually get asked on the job. Enough reps to make SQL automatic.

A retro computer showing a SQL query marked correct with a green checkmark.
Instant AI feedback

Write a query. Know if it's right in one second.

No copying an answer and hoping it clicked. The AI grader checks your real query against real data, catches exactly what's wrong, and explains the fix in plain English, like a senior analyst reading over your shoulder on every problem.

A circular mastery progress dial filling from blue to green, the SQLMaxx diamond at its center.
Mastery tracking

Stop guessing whether you actually know it.

SQLMaxx tracks every concept and shows you what you've mastered and what's still shaky. Your skills fill in one concept at a time, so 'I think I get joins' becomes something you can prove.

A SQL query editor circled by a blue return arrow with a clock, scheduled to come back for review.
Spaced review

Learn it once. Keep it for good.

Most of what you learn this week fades by next week. So when a concept comes due for review, SQLMaxx hands you a fresh problem to solve from a blank editor, not a flashcard to re-read. A research-backed spaced-repetition algorithm (FSRS) times each return for right before you'd forget, so your SQL is still there months later, when the interview or the job actually needs it.

Practice, feedback, mastery, review. That's the loop that turns reading into real skill.

Start free

No account, no credit card. Start solving in under a minute.