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
- Projecting Columns and Aliasing Pitfalls
- Computed Columns and Expression Precedence
- DISTINCT vs GROUP BY for Uniqueness
- CASE Expressions in SELECT