N009-H1 Tier 1 · Foundations · hard

Returns net profit in a column with that exact name

Part of Column Aliases and Expression Naming in SQL

The problem

An external financial reporting system ingests data and requires a column named exactly NetProfit — capital N, capital P, no spaces or underscores. The figure is $9,500 in revenue minus $4,200 in costs.

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

Output:

  • A single row with one column named exactly NetProfit — the column header must preserve the capital letters.

Run previews · Check grades

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

Worked solution Try it yourself first
Solution query
SELECT
  9500 - 4200 AS "NetProfit"

The shape

The double quotes around "NetProfit" are what keep the capital N and capital P intact. Without them, PostgreSQL silently folds the alias to netprofit, and the external reporting system rejects the column.

Clause by clause

  • SELECT 9500 - 4200 evaluates the subtraction and returns 5300 — revenue minus costs. Both operands are integer literals, so the result is the integer 5300.
  • AS "NetProfit" labels the output column with the exact header the external system needs. The double quotes tell PostgreSQL to take the case literally: capital N, capital P, no folding. The query that produced 5300 now hands it over with the right header.

Why this and not AS NetProfit

AS NetProfit is a syntactically valid alias. PostgreSQL accepts it without complaint, runs the query, and returns the right number. The column header that comes back is netprofit — all lowercase. The capitals were dropped during parsing, not at the end; the unquoted identifier was lowercased before it ever became a column name.

The gap between what you wrote and what the database stored is silent. The query ran. The number is correct. The only thing wrong is the header, and the only place that surfaces is when the external reporting system tries to find a column called NetProfit and doesn't find one. Whenever a downstream consumer is case-sensitive, the alias has to be quoted at the source. Renaming the column in the export step is extra work; quoting at the source is one pair of characters.

The trap

The trap here is the silence. There's no error, no warning, no flag in the result. The query runs, returns the right number, and the column header looks fine when you scan the output in the editor — netprofit is recognisable enough that the lowercase doesn't jump out. The mismatch only surfaces downstream, often in another team's tooling, sometimes hours later. Any alias that needs to keep its case takes double quotes — every time, no exceptions. The rule is the fix; remembering to apply it is the discipline.

You practiced quoting an alias to preserve case. PostgreSQL silently lowercases unquoted identifiers — even when the alias is otherwise legal — so any time the downstream system is case-sensitive, double quotes are non-optional.

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.