Mathematical Operators
Part of the Fundamentals section of Coddy's SQL journey. Lesson 23 of 72.
| Operator | Operation |
|---|---|
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
SELECT price + 10 as increased_price,
price - 10 as reduced_price,
price * 10 as multiple_price,
price / 2 as half_price
FROM products;- Integer ÷ Integer = Integer (truncated):
7 / 2 = 3(not 3.5)
- Integer ÷ Float = Float:
7 / 2.0 = 3.5
- Float ÷ Integer = Float:
7.0 / 2 = 3.5
Challenge
EasyAvailable tables and columns:
products:id,price,quantity
Create two calculated columns:
- First column named
high_mix_op:- Take the price column
- Multiply it by 2
- Subtract 20 from the result
- Second column named
low_mix:- Take the quantity column
- Divide it by 1.5
- Add 5 to the result
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 columnsPractice on your own: SQL playground