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
EasyAvailable tables and columns:
<strong>products</strong>:<strong>id</strong>,<strong>price</strong>,<strong>quantity</strong>
Create a query that calculates the following:
- A column called
total_valuethat multiplies the price by quantity and adds a fixed shipping cost of 15 - A column called
discounted_valuethat:- 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
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns