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,000multiplied 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, andannual_target.
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
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_numberis 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_targetcomputes the quarterly target inline: the quarter number times the $1,000 base, returning3000. Both operands are integers, so the result is the integer3000— clean for a planning template.3 * 1000 * 4 AS annual_targetcomputes 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 thequarterly_targetalias. Returns12000.
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.