SQL Arithmetic Operators
This page contains all the information, learn about SQL Arithmetic Operators concept in the SQL table with the help of examples.
The Arithmetic Operators is used to perform mathematical calculations on the numerical records or the value stored in the SQL table. The Arithmetic operator operates on two expressions like the addition of two values, subtraction of two values, multiplication of two values, division, and the modulus of two values. This operation is also performed on the columns of the SQL table.
The operator which comes under the arithmetic operator is as follows:
1 SQL Addition Operators (+)
2 SQL Subtraction Operators (-)
3 SQL Multiplication Operators (*)
4 SQL Division Operators (/)
Consider the already existing table named Diploma_Student:
Student_Id | Student_Name | First_Sem | Second_Sem | Third_Sem | Fourth_Sem | Fifth_Sem | Sixth_Sem | Total | Department_Id |
202111 | Vaishnavi Patil | 94 | 91 | 88 | 85 | 95 | 92 | 91 | 1 |
202112 | Vaibhav Lokhande | 85 | 90 | 92 | 80 | 85 | 82 | 86 | 2 |
202113 | Yash Dhull | 90 | 88 | 94 | 87 | 85 | 90 | 89 | 3 |
202114 | Sonali Patole | 95 | 90 | 92 | 88 | 92 | 90 | 91 | 4 |
202115 | Axar Patel | 85 | 80 | 82 | 86 | 92 | 84 | 85 | 1 |
202116 | Meena Mishra | 78 | 75 | 80 | 74 | 85 | 77 | 78 | 3 |
202117 | Mahesh Kumbhar | 75 | 80 | 75 | 78 | 80 | 76 | 77 | 5 |
202118 | Sakashi Patil | 80 | 78 | 74 | 78 | 80 | 77 | 78 | 2 |
202119 | Sopan Bhore | 70 | 68 | 75 | 75 | 80 | 80 | 75 | 2 |
202220 | Prajwal Lokhande | 80 | 85 | 85 | 75 | 78 | 80 | 81 | 4 |
202221 | Anuja Wanare | 85 | 88 | 86 | 82 | 84 | 85 | 85 | 5 |
202222 | Venkatesh Iyer | 90 | 89 | 87 | 90 | 92 | 91 | 90 | 3 |
202223 | Anushka Sen | 70 | 75 | 71 | 74 | 80 | 78 | 75 | 1 |
202224 | Aakash Jain | 80 | 75 | 72 | 74 | 85 | 80 | 78 | 4 |
202225 | Akshay Agarwal | 85 | 80 | 78 | 88 | 90 | 82 | 84 | 5 |
1 SQL Addition Operators (+)
The SQL Addition operator is used to perform mathematical calculations on the numeric records of the given tables. You can use the addition operator to add the numeric values of the given columns from the mentioned table in the query by specifying column names as the operand.
The syntax of the SQL Addition operator is as follows:
SELECT Column_Name1, Column_Name_2, Column_Name_3 + Column_Name_4 FROM Table_Name;
Let’s understand how to execute addition operators in the SQL queries with the help of some examples.
Example 1: Execute a query to add First_Sem, Second_Sem, Third_Sem, Fourth_Sem, Fifth_Sem, and Sixth_Sem columns from the Diploma_Student.
SELECT Student_Id, Student_Name, First_Sem + Second_Sem + Third_Sem + Fourth_Sem + Fifth_Sem + Sixth_Sem AS 'Addition of Percentage', Department_Id FROM Diploma_Student;
In the above addition operator example, we have displayed the student id and student name and performed addition operations on First_Sem, Second_Sem, Third_Sem, Fourth_Sem, Fifth_Sem, and Sixth_Sem columns named column as ‘Addition of Percentage’. We have performed an addition operation on the multiple columns.
The output of the above query is as follows:
Student_Id | Student_Name | Addition of Percentage | Department_Id |
202111 | Vaishnavi Patil | 545 | 1 |
202112 | Vaibhav Lokhande | 514 | 2 |
202113 | Yash Dhull | 534 | 3 |
202114 | Sonali Patole | 547 | 4 |
202115 | Axar Patel | 409 | 1 |
202116 | Meena Mishra | 469 | 3 |
202117 | Mahesh Kumbhar | 464 | 5 |
202118 | Sakashi Patil | 467 | 2 |
202119 | Sopan Bhore | 448 | 2 |
202220 | Prajwal Lokhande | 483 | 4 |
202221 | Anuja Wanare | 510 | 5 |
202222 | Venkatesh Iyer | 539 | 3 |
202223 | Anushka Sen | 448 | 1 |
202224 | Aakash Jain | 466 | 4 |
202225 | Akshay Agarwal | 503 | 5 |
Example 2: Execute a query to perform an addition operation on the total field from the diploma_Student table.
SELECT Student_Id, Student_Name, Total + 3 AS 'Add Percentage', Department_Id FROM Diploma_Student;
In the above Addition operator query example, we added 3 percentages to each student to the Total Fields.
The output of the above query is as follows:
Student_Id | Student_Name | Add Percentage | Department_Id |
202111 | Vaishnavi Patil | 94 | 1 |
202112 | Vaibhav Lokhande | 89 | 2 |
202113 | Yash Dhull | 92 | 3 |
202114 | Sonali Patole | 94 | 4 |
202115 | Axar Patel | 88 | 1 |
202116 | Meena Mishra | 81 | 3 |
202117 | Mahesh Kumbhar | 80 | 5 |
202118 | Sakashi Patil | 81 | 2 |
202119 | Sopan Bhore | 78 | 2 |
202220 | Prajwal Lokhande | 84 | 4 |
202221 | Anuja Wanare | 88 | 5 |
202222 | Venkatesh Iyer | 93 | 3 |
202223 | Anushka Sen | 78 | 1 |
202224 | Aakash Jain | 81 | 4 |
202225 | Akshay Agarwal | 87 | 5 |
2 SQL Subtraction Operators (+):
The SQL Subtraction operator is used to perform mathematical calculations on the numeric records of the given tables. We can use the subtraction operator to subtract the numeric values of the given columns from the mentioned table in the query by specifying column names as the operand.
The syntax of the SQL Subtraction operator is:
SELECT Column_Name1, Column_Name_2, Column_Name_3 - Column_Name_4 FROM Table_Name;
Let’s understand how to execute subtraction operators in SQL queries with the help of some examples.
Example: Execute a query to subtract Sixth sem values from the Fifth sem values.
SELECT Student_Id, Student_Name, Fifth_Sem - Sixth_Sem AS 'Subtraction of values', Department_Id FROM Diploma_Student;
In the above subtraction operator query example, we subtract the sixth Sem values from the fifth Sem values.
The output of the above query is:
Student_Id | Student_Name | Subtraction of values | Department_Id |
202111 | Vaishnavi Patil | 3 | 1 |
202112 | Vaibhav Lokhande | 3 | 2 |
202113 | Yash Dhull | -5 | 3 |
202114 | Sonali Patole | 2 | 4 |
202115 | Axar Patel | 8 | 1 |
202116 | Meena Mishra | 8 | 3 |
202117 | Mahesh Kumbhar | 4 | 5 |
202118 | Sakashi Patil | 3 | 2 |
202119 | Sopan Bhore | 0 | 2 |
202220 | Prajwal Lokhande | -2 | 4 |
202221 | Anuja Wanare | -1 | 5 |
202222 | Venkatesh Iyer | 1 | 3 |
202223 | Anushka Sen | 2 | 1 |
202224 | Aakash Jain | 5 | 4 |
202225 | Akshay Agarwal | 8 | 5 |
3 SQL Multiplication Operators (+):
The SQL Multiplication operator is used to perform mathematical calculations on the numeric records of the given tables. We can use the Multiplication operator to multiply the numeric values of the given columns from the mentioned table in the query by specifying column names as the operand.
The syntax of the SQL Multiplication operator is:
SELECT Column_Name1, Column_Name_2 * Column_Name_3, Column_Name_4 FROM Table_Name;
Let’s understand how to execute Multiplication operators in the SQL queries with the help of some examples.
Example: Execute a query to multiply the first sem column by 2.
SELECT Student_Id, Student_Name, First_Sem * 2 AS 'Multiplied by 2', Department_Id FROM Diploma_Student;
In the above multiplication operator query example, we multiplied the first sem column value by 2.
The output of the above query is as follows:
Student_Id | Student_Name | Multiplied by 2 | Department_Id |
202111 | Vaishnavi Patil | 188 | 1 |
202112 | Vaibhav Lokhande | 170 | 2 |
202113 | Yash Dhull | 180 | 3 |
202114 | Sonali Patole | 190 | 4 |
202115 | Axar Patel | 170 | 1 |
202116 | Meena Mishra | 156 | 3 |
202117 | Mahesh Kumbhar | 150 | 5 |
202118 | Sakashi Patil | 160 | 2 |
202119 | Sopan Bhore | 140 | 2 |
202220 | Prajwal Lokhande | 160 | 4 |
202221 | Anuja Wanare | 170 | 5 |
202222 | Venkatesh Iyer | 180 | 3 |
202223 | Anushka Sen | 140 | 1 |
202224 | Aakash Jain | 160 | 4 |
202225 | Akshay Agarwal | 170 | 5 |
4 SQL Division Operators (+):
The SQL Division operator is used to perform mathematical calculations on the numeric records of the given tables. We can use the Division operator to divide the numeric values of the given columns from the mentioned table in the query by specifying column names as the operand.
The syntax of the SQL Division operator is as follows:
SELECT Column_Name1, Column_Name_2 / Column_Name_3, Column_Name_4 FROM Table_Name;
Let’s understand how to execute Division operators in the SQL queries with the help of some examples.
Example: Execute a query to add First_Sem, Second_Sem, Third_Sem, Fourth_Sem, Fifth_Sem, and Sixth_Sem columns and divide the value by 6.
SELECT Student_Id, Student_Name, (First_Sem + Second_Sem + Third_Sem + Fourth_Sem + Fifth_Sem + Sixth_Sem)/6 AS 'Division Operation', Department_Id FROM Diploma_Student;
In the above Division operator query example, we first added values from the First_Sem, Second_Sem, Third_Sem, Fourth_Sem, Fifth_Sem, and Sixth_Sem and then divided the value by 6. We performed multiple operations in the above query.
The output of the above query is as follows:
Student_Id | Student_Name | Division Operation | Department_Id |
202111 | Vaishnavi Patil | 90.8333 | 1 |
202112 | Vaibhav Lokhande | 85.6667 | 2 |
202113 | Yash Dhull | 89.0000 | 3 |
202114 | Sonali Patole | 91.1667 | 4 |
202115 | Axar Patel | 84.8333 | 1 |
202116 | Meena Mishra | 78.1667 | 3 |
202117 | Mahesh Kumbhar | 77.3333 | 5 |
202118 | Sakashi Patil | 77.8333 | 2 |
202119 | Sopan Bhore | 74.6667 | 2 |
202220 | Prajwal Lokhande | 80.5000 | 4 |
202221 | Anuja Wanare | 85.0000 | 5 |
202222 | Venkatesh Iyer | 89.8333 | 3 |
202223 | Anushka Sen | 74.6667 | 1 |
202224 | Aakash Jain | 77.6667 | 4 |
202225 | Akshay Agarwal | 83.8333 | 5 |