Arithmetic operators
- SQL course
- Beginner
- Lesson 30/115
- 4 min
Learn +, -, *, /, % arithmetic operators.
Arithmetic operators
SQL uses +, -, *, /, % arithmetic operators in SELECT to compute values.
SELECT price * 1.18 AS kdvli FROM products;This query multiplies price by 1.18; adds tax.
price * 1.18 AS kdvli is selected from products.
Arithmetic operators — details
Modulus % gives the remainder of division. For integer division use FLOOR or CAST depending on the database.
Practice Arithmetic operators
Select price times 1.18 aliased as with_tax from products.
Starter code
-- compute tax
SELECT
FROM productsSample solution
SELECT price * 1.18 AS kdvli
FROM productsExpected output
kdvli 5.90 14.16
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which operator gives the remainder?
- /
- % Correct answer
- //
- MOD
Explanation: % (modulo) returns the remainder of a division; 10 % 3 gives 1.
2 Multiplication
SELECT price ____ 2 FROM products;
SELECT price * 2 FROM products;
Explanation: * is the multiplication operator; price * 2 gives double the price.
3 Arithmetic operators: match the terms
| Term | Meaning |
|---|---|
+ |
add |
- |
subtract |
* |
multiply |
/ |
divide |