N011-H1 Tier 1 · Foundations · hard

Return both values in a single row

Part of Arithmetic and Comparison Expressions in SQL

The problem

Brightlane's finance team is preparing two bonus figures for an audit trail. A $10,000 pool is divided equally among 3 staff members, and the report must show both:

  • The whole-dollar amount each person receives under strict equal integer allocation.
  • The exact decimal share, including fractional cents.

Write a query to return both values in a single row.

Output:

  • A single row with two columns: integer_share (whole dollars) and exact_share (decimal with full precision).

Run previews · Check grades

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

Worked solution Try it yourself first
Solution query
SELECT
  10000 / 3 AS integer_share,
  10000::NUMERIC / 3 AS exact_share

The shape

The same two numbers divided two different ways. The first expression keeps both operands as integers and truncates to a whole-dollar share; the second casts one operand to numeric and preserves the fractional cents. Two columns, side by side, make the contrast visible on a single row.

Clause by clause

  • 10000 / 3 AS integer_share divides two integers. PostgreSQL applies integer division, the fractional part is dropped before the result lands, and the column returns 3333. That's the whole-dollar amount each staff member receives under strict equal integer allocation — the figure the audit needs first.
  • 10000::numeric / 3 AS exact_share casts the left operand to numeric before the division. With one operand now numeric, PostgreSQL promotes the other to match and computes in decimal arithmetic, returning 3333.333.... The fractional cents survive into the result because the cast happens before the operator evaluates.
  • The comma between the two expressions is what puts both columns in the same row. Each expression sources from the same literals (10000 and 3); the only difference between them is the cast on the left operand of the second.

Why this and not two separate queries

The audit report has to show both figures together. Running two queries and assembling the result afterward works, but it loses the side-by-side contrast that makes the report readable. Pairing the columns makes it obvious that the same arithmetic with different operand types produces different answers — 3333 versus 3333.333... — and that the difference is real, not a rounding artifact. The AS aliases also encode which figure is which directly into the column names, so the result survives into whatever spreadsheet or report it feeds into.

The trap

The two expressions look almost identical. The only difference is the ::numeric cast, and it sits at the very start of the second expression where a quick read might miss it. Drop the cast on exact_share and both columns return 3333 — the audit silently loses the fractional cents on the column that was supposed to preserve them. Cast presence is what separates the two calculations; once both operands are integers, the truncation is already done by the time anything downstream can react to it.

You practiced producing two values from the same numbers — one with integer division, one with decimal division — in a single query. The recurring lesson: identical operands plus different operand types yield different results, and naming both columns side by side is how an audit report makes that contrast visible.

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.