AnalystPracticeGuides
DashboardSign up

SQL aliases and calculated columns

AS gives a column or table a short, readable name. You can also calculate new columns in SELECT, such as price times quantity. An alias from SELECT can't be used in WHERE, because WHERE runs first.

Watch it solved. Q5: percentages and integer division, from 3:06, in our video “SQL Interview Questions and Answers for Data Analysts (Easy to Hard)”. Pressing play loads the video from YouTube (privacy). Open on YouTube

How do you calculate a column?

SELECT order_id,
price * quantity AS revenue,
ROUND(price * quantity * 0.2, 2) AS vat
FROM order_lines;

How do table aliases help?

SELECT c.name, o.amount
FROM customers AS c
JOIN orders AS o ON o.customer_id = c.id;

Short aliases keep joins readable and make it clear which table each column comes from.

Why can't I use my alias in WHERE?

The database runs FROM and WHERE before SELECT, so revenue doesn't exist yet. Repeat the expression, WHERE price * quantity > 100, or wrap the query in a subquery or CTE. ORDER BY runs last, so ORDER BY revenue works everywhere.

Common mistakes

Dividing two whole numbers can return a whole number in some databases (5 / 2 = 2), so multiply by 1.0 first. Aliases with spaces need quotes, as in AS "order total", so prefer underscores.

Try it yourself. Practise this in a real database in your browser, with instant feedback.
Practise aliases and arithmetic

Updated November 2026.

← All free guides