N009-M2 Tier 1 · Foundations · medium

Returns net revenue in a column with that exact name

Part of Column Aliases and Expression Naming in SQL

The problem

A finance analyst is building a P&L export for the board deck. The output must contain a column named exactly Net Revenue — two words, with a space, capital N and capital R. Net revenue is gross revenue of $8,500 minus $1,200 in returns.

Write a query that returns net revenue in a column with that exact name.

Output:

  • A single row with one column named exactly Net Revenue. To preserve the space and the case, the alias must be wrapped in double quotes: AS "Net Revenue".

Run previews · Check grades

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

Worked solution Try it yourself first
Solution query
SELECT
  8500 - 1200 AS "Net Revenue"

The shape

The double quotes around "Net Revenue" are what preserve the space and the capital letters in the column header. Without them, the alias is illegal as written.

Clause by clause

  • SELECT 8500 - 1200 evaluates the subtraction and returns 7300 — gross revenue minus returns. Both operands are integer literals, so the result is the integer 7300.
  • AS "Net Revenue" labels the output column with the exact header the board deck needs. The double quotes do two things at once: they let the alias contain a space (an unquoted identifier has to be a single contiguous token), and they tell PostgreSQL to take the case literally instead of folding it.

Why this and not AS Net Revenue or AS net_revenue

AS Net Revenue is a syntax error. PostgreSQL reads Net as the alias and then sees Revenue as an unexpected token sitting in the wrong place in the SELECT list. The space breaks the identifier.

AS net_revenue is a legal alias and a normal habit elsewhere. It's the right shape when you control the downstream consumer; it's the wrong shape here because the board deck requires the header Net Revenue with the space and the capitals intact. Quoting the alias at the source is one pair of characters; renaming the column after the fact is extra work.

The trap

Double quotes feel similar to single quotes, and the muscle memory from string literals is to reach for single quotes. They mean different things in SQL. Single quotes are for string values — 'Net Revenue' would be a literal string sitting in the SELECT list as a data value, not an alias. Double quotes are for identifiers. Use the wrong one and the query either errors or runs but produces a column with the wrong header. Whenever an alias needs to keep its case or contain a space, the quotes must be double quotes.

You practiced wrapping an alias in double quotes to preserve spaces and case. Unquoted identifiers fold to lowercase and forbid spaces — double quotes are the recurring fix any time the downstream consumer requires an exact column header.

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.