N009-M1 Tier 1 · Foundations · medium

Return all three figures in one row

Part of Column Aliases and Expression Naming in SQL

The problem

A sales planning template needs a single row with three figures for the current quarter:

  • The quarter number is 3.
  • The quarterly target is $1,000 multiplied by the quarter number.
  • The annual target is the quarterly target multiplied by 4.

Write a query to return all three figures in one row.

Output:

  • A single row with three columns: quarter_number, quarterly_target, and annual_target.

Run previews · Check grades

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

Worked solution Try it yourself first
Solution query
SELECT
  3 AS quarter_number,
  3 * 1000 AS quarterly_target,
  3 * 1000 * 4 AS annual_target

The shape

Three comma-separated expressions, each with its own alias, produce a three-column row that already reads as the planning template — the quarter number, the quarterly target derived from it, and the annual target derived from the quarterly.

Clause by clause

  • 3 AS quarter_number is a labeled integer literal — the current quarter, named so the row reads as a planning record rather than as anonymous numbers.
  • 3 * 1000 AS quarterly_target computes the quarterly target inline: the quarter number times the $1,000 base, returning 3000. Both operands are integers, so the result is the integer 3000 — clean for a planning template.
  • 3 * 1000 * 4 AS annual_target computes the annual target the same way the prompt describes it — quarterly target times four — but written out from the underlying literals rather than referring to the quarterly_target alias. Returns 12000.

Why this and not reuse the quarterly_target alias

The natural shape would be quarterly_target * 4, since that's the business description. SQL won't allow it inside the same SELECT list. Every expression in SELECT evaluates against the same input at the same time; the aliases only exist as labels on the way out. By the time quarterly_target is a usable name, the row is already finished. So the annual target has to be written from the same literals the quarterly target uses — 3 * 1000 * 4 — even though it reads as a duplication of work.

The trade-off is real. Three expressions, two of them sharing the same 3 * 1000 substring, all inside a single SELECT. At this scale the repetition is the cost of producing a multi-column row in one query. Once subqueries enter the picture there are ways to compute a value once and reuse it; for now, the inline repetition is the shape.

You practiced building a row from three independent expressions, each with its own alias. The recurring shape: every column of a single-row template is an expression in the SELECT list, named via AS — the rest of the query (no FROM, no WHERE) is empty.

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.