CodeBlanks Logo Icon CodeBlanks

Arithmetic operators

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

query.sql
-- compute tax
SELECT
FROM products

Sample solution

query.sql
SELECT price * 1.18 AS kdvli
FROM products

Expected 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

Question
SELECT price ____ 2 FROM products;
Answer
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

All lessons in Beginner