×

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_IdStudent_NameFirst_SemSecond_SemThird_SemFourth_SemFifth_SemSixth_SemTotalDepartment_Id
202111Vaishnavi Patil949188859592911
202112Vaibhav Lokhande859092808582862
202113Yash Dhull908894878590893
202114Sonali Patole959092889290914
202115Axar Patel858082869284851
202116Meena Mishra787580748577783
202117Mahesh Kumbhar758075788076775
202118Sakashi Patil807874788077782
202119Sopan Bhore706875758080752
202220Prajwal Lokhande808585757880814
202221Anuja Wanare858886828485855
202222Venkatesh Iyer908987909291903
202223Anushka Sen707571748078751
202224Aakash Jain807572748580784
202225Akshay Agarwal858078889082845

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_IdStudent_NameAddition of PercentageDepartment_Id
202111Vaishnavi Patil5451
202112Vaibhav Lokhande5142
202113Yash Dhull5343
202114Sonali Patole5474
202115Axar Patel4091
202116Meena Mishra4693
202117Mahesh Kumbhar4645
202118Sakashi Patil4672
202119Sopan Bhore4482
202220Prajwal Lokhande4834
202221Anuja Wanare5105
202222Venkatesh Iyer5393
202223Anushka Sen4481
202224Aakash Jain4664
202225Akshay Agarwal5035
SQL Arithmetic Operators

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_IdStudent_NameAdd PercentageDepartment_Id
202111Vaishnavi Patil941
202112Vaibhav Lokhande892
202113Yash Dhull923
202114Sonali Patole944
202115Axar Patel881
202116Meena Mishra813
202117Mahesh Kumbhar805
202118Sakashi Patil812
202119Sopan Bhore782
202220Prajwal Lokhande844
202221Anuja Wanare885
202222Venkatesh Iyer933
202223Anushka Sen781
202224Aakash Jain814
202225Akshay Agarwal875
SQL Arithmetic Operators

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_IdStudent_NameSubtraction of valuesDepartment_Id
202111Vaishnavi Patil31
202112Vaibhav Lokhande32
202113Yash Dhull-53
202114Sonali Patole24
202115Axar Patel81
202116Meena Mishra83
202117Mahesh Kumbhar45
202118Sakashi Patil32
202119Sopan Bhore02
202220Prajwal Lokhande-24
202221Anuja Wanare-15
202222Venkatesh Iyer13
202223Anushka Sen21
202224Aakash Jain54
202225Akshay Agarwal85
SQL Arithmetic Operators

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_IdStudent_Name Multiplied by 2Department_Id
202111Vaishnavi Patil1881
202112Vaibhav Lokhande1702
202113Yash Dhull1803
202114Sonali Patole1904
202115Axar Patel1701
202116Meena Mishra1563
202117Mahesh Kumbhar1505
202118Sakashi Patil1602
202119Sopan Bhore1402
202220Prajwal Lokhande1604
202221Anuja Wanare1705
202222Venkatesh Iyer1803
202223Anushka Sen1401
202224Aakash Jain1604
202225Akshay Agarwal1705
SQL Arithmetic Operators

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_IdStudent_NameDivision OperationDepartment_Id
202111Vaishnavi Patil90.83331
202112Vaibhav Lokhande85.66672
202113Yash Dhull89.00003
202114Sonali Patole91.16674
202115Axar Patel84.83331
202116Meena Mishra78.16673
202117Mahesh Kumbhar77.33335
202118Sakashi Patil77.83332
202119Sopan Bhore74.66672
202220Prajwal Lokhande80.50004
202221Anuja Wanare85.00005
202222Venkatesh Iyer89.83333
202223Anushka Sen74.66671
202224Aakash Jain77.66674
202225Akshay Agarwal83.83335
SQL Arithmetic Operators

Related Topics

SQL HAVING Clause

In this tutorial, we will understand the HAVING clause concept in SQL with the help of examples. The HAVING Clause in the SQL is used as we cannot use the WHERE...

3 minutes read.

SQL CASE

This page contains all the information about SQL CASE. The CASE is an If-Else type of logical query used in the statement. The CASE in Structured Query Language is similar...

5 minutes read.

SQL Except

In SQL, we probably use the JOIN clause to receive the combined result from one or more than one table. But sometimes, we want a result that contains data from...

4 minutes read.

What is SQL Injection?

Introduction to SQL Injection SQL injection is a vulnerability or a technique that might destroy the database of a website or a web application. It is one of the most widely...

4 minutes read.

SQL Comparision Operator

The Comparison Operator compares different data of the Structured Query Language table and checks whether the data are the same, less than, greater than, less than, or greater than equal....

14 minutes read.

SQL Topological Sorting

It is for Directed Acyclic Graph, which linearly describes the ordering of graphs. It is not possible for all graphs, it is possible for only Directed acyclic graphs. Applications of Topological...

3 minutes read.

SQL UNION ALL Operator

This page has all the information about UNION ALL operator, which is used to join all the values from the SELECT queries. Similar records were not considered in the result in...

3 minutes read.

SQL Primary Key

A field, which contains unique data in a table, is called a PRIMARY KEY (PK). It means, a PRIMARY KEY field must contain unique data in the table. A PRIMARY KEY...

4 minutes read.

SQL DELETE

In this tutorial, you will learn about the SQL DELETE concept by using examples. In Structured Query Language (SQL), we fetch the data from the database table using SELECT Statement and...

3 minutes read.

How to use the BETWEEN operator in SQL

In this entire SQL article, we will understand and learn about the BETWEEN operator concept and how to use it in SQL. What is the BETWEEN operator in SQL? The Between operator...

4 minutes read.

Nth highest salary

The most common and important question asked in interviews that how we can find the Nth highest salary in a table (2nd highest salary, 3rd highest salary, or Nth highest...

6 minutes read.

TCL Commands in SQL

In Structured Query Language, TCL is an abbreviation for Transaction Control Language. A single unit of work in a database is formed after the consecutive execution of commands is known...

6 minutes read.

How to delete a row in SQL

Introduction To delete or remove the unused/unwanted rows from a table, DELETE command is used in SQL.DELETE command removes the entire record from a table.The DELETE statement can delete one or...

6 minutes read.

Introduction to SQL

SQL Introduction SQL is Standard Query Language. This language is used to communicate or interact with database. In other words, SQL is used to access and manage data or information...

2 minutes read.

Codd’s Rules in SQL

Codd’s Rules Dr. Edgar F. Codd, in 1985, laid down 13 fundamental rules after doing large-scale research on the Relational Model of databases. According to him, every database must follow these...

3 minutes read.

SQL ORDER BY

SQL ORDER BY The SQL ORDER BY clause is used to sort the data stored in tables in the database. The sorting can be done in an ascending way, descending way,...

5 minutes read.

How to delete column in table

Introduction In SQL, sometimes it is required to delete a column of a table.The use of ALTER TABLE command with DROP COLUMN clause will serve the purpose to delete/remove a column...

4 minutes read.

SQL CONSTRAINTS

SQL Constraints specifies the rules/limitations/restrictions for data present in table. SQL Constraints are specified at the time of table creation or after table creation using ALTER command. There are two...

5 minutes read.

SQL LOGICAL Operator

In this tutorial, we will understand the operator who falls under the logical operator in SQL with the help of examples. The SQL Logical Operator displays the query result in one...

5 minutes read.

SQL VIEW

The SQL VIEW concept helps to hide the difficulty of the records and provides limitations to access to the database. The SQL view is similar to the SQL tables. In SQL...

7 minutes read.