0PricingLogin
SQL Interview Prep · Lesson

Computed Columns and Expression Precedence

Arithmetic, concatenation, and operator precedence inside SELECT lists.

Computed Columns in SELECT

A computed column is an expression in SELECT that derives a value instead of reading one directly — like price * quantity. Always give it a clean alias.

SELECT product,
       price,
       quantity,
       price * quantity AS line_total
FROM order_items;

Arithmetic Operators

SQL has the math operators you'd expect: +, -, *, /, plus a modulo. The result's type follows the operands — and that's where the next gotcha hides.

SELECT 7 + 3 AS sum_val,
       7 - 3 AS diff_val,
       7 * 3 AS prod_val,
       7 % 3 AS remainder;

All lessons in this course

  1. Projecting Columns and Aliasing Pitfalls
  2. Computed Columns and Expression Precedence
  3. DISTINCT vs GROUP BY for Uniqueness
  4. CASE Expressions in SELECT
← Back to SQL Interview Prep