SQL Arithmetic Operators

The SQL reserved words and characters are called operators, which are used with a WHERE clause in a SQL query. In SQL, an operator can either be a unary or binary operator. The unary operator uses only one operand for performing the unary operation, whereas the binary operator uses two operands for performing the binary operation.

Syntax of SQL Operator

Operator SQL_Operand

SQL Arithmetic Operators

The Arithmetic Operators perform the mathematical operation on the numerical data of the SQL tables. These operators perform addition, subtraction, multiplication, and division operations on the numerical operands.

Following are the various arithmetic operators performed on the SQL data:

  1. SQL Addition Operator (+)

  2. SQL Subtraction Operator (-)

  3. SQL Multiplication Operator (+)

  4. SQL Division Operator (-)

  5. SQL Modulus Operator (+)

SQL Addition Operator (+)

The SQL Addition Operator performs the addition on the numerical columns in the table.

If you want to add the values of two numerical columns in the table, then you have to specify both columns as the first and second operand. You can also add the new integer value in the value of the integer column.

SELECT Column_Name_1 Addition_Operator Column_Name2 FROM Table_Name;

Example:

SELECT Emp_Salary + Emp_Bonus AS Emp_Total_Salary FROM Employee;

SQL Subtraction Operator (-)

The SQL Subtraction Operator performs the subtraction on the numerical columns in the table.

If we want to subtract the values of one numerical column from the values of another numerical column, then we have to specify both columns as the first and second operand. We can also subtract the integer value from the values of the integer column.

SELECT Column_Name_1 Subtraction_Operator Column_Name2 FROM Table_Name;

Example

SELECT Emp_Panelty - Emp_Salary AS Emp_Total_Salary FROM Employee WHERE Employee_ID = 104;

SQL Multiplication Operator (*)

The SQL Multiplication Operator performs the multiplication on the numerical columns in the table.

If you want to multiply the values of two numerical columns, then you have to specify both columns as the first and second operand. You can also multiply the integer value with the values of an integer column.

SELECT Column_Name_1 Multiplication_Operator Column_Name2 FROM Table_Name;

Example:

SELECT Car_Amount * Car_Price AS Car_Total_Price FROM Cars;

SQL Division Operator (/)

The SQL Division operator divides the numerical values of one column by the numerical values of another column.

SELECT Column_Name_1 Division_Operator Column_Name2 FROM Table_Name;

Example:

SELECT Car_Price / Car_Amount AS One_Car_Price FROM Cars;

SQL Modulus Operator (%)

The SQL Modulus Operator provides the remainder when the numerical values of one column are divided by the numerical values of another column.

SELECT Column_Name_1 Modulus_Operator Column_Name2 FROM Table_Name;

Example:

SELECT Student_English % Student_Maths AS Remainder FROM Student;

These are all the arithmetic operators.