Menu
Coddy logo textTech

Mathematical Columns

Part of the Fundamentals section of Coddy's SQL journey — lesson 24 of 72.

You can combine multiple columns and numbers in complex expressions. For example:

SELECT (price * quantity) + shipping_cost as final_price
FROM orders;

You can also use parentheses to control the order of operations:

SELECT (base_salary + bonus) * (1 - tax_rate) as net_pay
FROM payroll;
challenge icon

Challenge

Easy

Available tables and columns:

  • <strong>products</strong>: <strong>id</strong>, <strong>price</strong>, <strong>quantity</strong>

Create a query that calculates the following:

  1. A column called total_value that multiplies the price by quantity and adds a fixed shipping cost of 15
  2. A column called discounted_value that:
    • First multiplies the price by quantity
    • Then applies a 20% discount (multiply by 0.8)
    • Finally adds a fixed shipping cost of 10

Try to use parentheses appropriately to ensure the calculations are performed in the correct order!

Cheat sheet

You can combine multiple columns and numbers in complex expressions using arithmetic operators:

SELECT (price * quantity) + shipping_cost as final_price
FROM orders;

Use parentheses to control the order of operations:

SELECT (base_salary + bonus) * (1 - tax_rate) as net_pay
FROM payroll;

Try it yourself

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals