SQL Arithmetic Operators | SQL Tutorial - Learn with VOKS
Advance AI Bootstrap C C++ Computer Vision Content Writing CSS Cyber Security Data Analysis Deep Learning Email Marketing Excel Figma HTML Java Script Machine Learning MySQLi Node JS PHP Power Bi Python Python for AI Python for Analysis React React Native SEO SMM SQL
Back Next

SQL Arithmetic Operators

Learn this topic step-by-step with VOKS Tutorials.

Arithmetic operators in SQL are used to perform mathematical operations on numeric columns. These are useful for calculating totals, differences, averages, and more.

1️⃣ Common Arithmetic Operators in SQL

| Operator | Description         | Example            |
|----------|-------------------|------------------|
| `+`      | Addition            | `Salary + Bonus`   |
| `-`      | Subtraction         | `Salary - Tax`     |
| `*`      | Multiplication      | `Quantity * Price` |
| `/`      | Division            | `Total / Count`    |
| `%`      | Modulus (remainder) | `Salary % 1000`    |

2️⃣ Using Arithmetic Operators in SQL

Suppose we have this table:

| EmployeeID | Name  | Salary | Bonus |
|------------|-------|--------|-------|
| 1          | John  | 3000   | 500   |
| 2          | Mary  | 3500   | 600   |
| 3          | David | 4000   | 800   |
| 4          | Anna  | 3200   | 400   |

a) Addition

SELECT Name, Salary + Bonus AS TotalCompensation
FROM Employees;

Output:

| Name  | TotalCompensation |
|-------|------------------|
| John  | 3500             |
| Mary  | 4100             |
| David | 4800             |
| Anna  | 3600             |

b) Subtraction

SELECT Name, Salary - Bonus AS NetSalary
FROM Employees;

Output:

| Name  | NetSalary |
|-------|-----------|
| John  | 2500      |
| Mary  | 2900      |
| David | 3200      |
| Anna  | 2800      |

c) Multiplication

SELECT Name, Bonus * 2 AS DoubleBonus
FROM Employees;

Output:

| Name  | DoubleBonus |
|-------|-------------|
| John  | 1000        |
| Mary  | 1200        |
| David | 1600        |
| Anna  | 800         |

d) Division

SELECT Name, Salary / 1000 AS SalaryInThousands
FROM Employees;

Output:

| Name  | SalaryInThousands |
|-------|------------------|
| John  | 3                |
| Mary  | 3.5              |
| David | 4                |
| Anna  | 3.2              |

e) Modulus (Remainder)

SELECT Name, Salary % 1000 AS Remainder
FROM Employees;

Output:

| Name  | Remainder |
|-------|-----------|
| John  | 0         |
| Mary  | 500       |
| David | 0         |
| Anna  | 200       |


-- Addition
SELECT Name, Salary + Bonus AS TotalCompensation
FROM Employees;

-- Subtraction
SELECT Name, Salary - Bonus AS NetSalary
FROM Employees;

-- Multiplication
SELECT Name, Bonus * 2 AS DoubleBonus
FROM Employees;

-- Division
SELECT Name, Salary / 1000 AS SalaryInThousands
FROM Employees;

-- Modulus
SELECT Name, Salary % 1000 AS Remainder
FROM Employees;
QUICK KNOWLEDGE CHECK

Test Your Understanding

Answer 5 questions generated from this lesson. Your result is calculated instantly and is not saved.

0 / 5 answered
All Courses
Advance AI Bootstrap C C++ Computer Vision Content Writing CSS Cyber Security Data Analysis Deep Learning Email Marketing Excel Figma HTML Java Script Machine Learning MySQLi Node JS PHP Power Bi Python Python for AI Python for Analysis React React Native SEO SMM SQL
Course contents
SQL
01 Introduction 02 What is a Database, Advantages of Database, and Database Tables 03 Creating Databases, Tables, Constraints, and Keys 04 Defining Data Types, Unique ID, Inserting Values, and Handling NULL 05 SELECT, DISTINCT, TOP, LIMIT, UPDATE, DELETE, ORDER BY, WHERE, HAVING, AND, OR, NOT 06 Aggregate function; Min, Max, Count, Avg, Sum 07 Wildcards, IN, AS, LIKE, BETWEEN, and Aliases 08 SQL Joins: Inner, Outer, Left, Right, Full, Cross 09 Set Theory for SQL: Joins, UNION, INTERSECT, EXCEPT, GROUP BY 10 SQL Arithmetic Operators 11 SQL Bitwise Operators 12 SQL Comparison Operator 13 SQL View/Null Functions 14 SQL Comments 15 SQL Case