N001-M1 Tier 1 · Foundations · medium

Return the base salary, commission amount, bonus, and total compensation in a single row

Part of SELECT and Column Expressions in SQL

The problem

Helix Systems' payroll administrator is preparing a monthly compensation statement for one of the sales representatives. The rep has a base salary of $5,200, earned commission at 8% on $9,500 in closed sales this month, and received a $350 performance bonus.

Write a query to return the base salary, commission amount, bonus, and total compensation in a single row.

Output:

  • A single row with four columns, in this order: base_salary, commission, bonus, and total_compensation.

Run previews · Check grades

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

Worked solution Try it yourself first
Solution query
SELECT
  5200 AS base_salary,
  9500 * 0.08 AS commission,
  350 AS bonus,
  5200 + 9500 * 0.08 + 350 AS total_compensation

The shape

Four labeled expressions, one for each piece of the compensation statement, with the total composed inline from the same numbers the breakdown columns are computing.

Clause by clause

  • 5200 AS base_salary is a literal — the rep's base, named as the domain quantity. Numeric literals don't need any operator; they just need a label to read as a column.
  • 9500 * 0.08 AS commission computes 8% commission on $9,500 in closed sales, returning 760.00. The decimal on 0.08 keeps the result in dollars-and-cents precision.
  • 350 AS bonus is another labeled literal, the performance bonus.
  • 5200 + 9500 * 0.08 + 350 AS total_compensation is the roll-up: base plus commission plus bonus. Standard operator precedence runs the multiplication before the additions, so the expression evaluates as 5200 + 760 + 350 and lands at 6310.00.

Why this and not total = base_salary + commission + bonus

The first three aliases — base_salary, commission, bonus — can't be reused inside the fourth expression. SQL evaluates every expression in the SELECT list against the same input at the same time; the aliases only come into being once the whole SELECT finishes, and at that point the row is already on its way out. So the arithmetic for the total has to be written out in full from the underlying literals.

The trade-off is real: the total expression repeats the multiplication that already lives in the commission expression. Once SQL has more tools available, there are tidier ways to define a value once and reuse it. At this level, the repetition is the price of working entirely inside SELECT.

You practiced composing several derived columns in a single SELECT and using one of them as a roll-up of the others. Same-row breakdown-plus-total composition recurs anywhere a query needs to show detail and summary together.

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.