SQL Tutorial

SQL Tutorial SQL Introduction SQL Syntax SQL OPERATORS SQL COMMANDS SQL Queries

SQL Table

SQL TABLE SQL CREATE TABLE SQL ALTER TABLE SQL DELETE SQL TRUNCATE TABLE SQL UPDATE TABLE

SQL SELECT

SQL SELECT Statement SQL SELECT IN Operator SQL BETWEEN Operator SQL SELECT BETWEEN Operator SQL SELECT AND Operator SQL SELECT DISTINCT SQL SELECT SUM SQL SELECT MAX SQL SELECT MIN SQL SELECT AVG

SQL Clause

SQL GROUP BY CLAUSE SQL ORDER BY Clause SQL HAVING Clause

SQL INSERT

SQL INSERT INTO Statement

SQL JOIN

SQL JOIN SQL Inner Join SQL Left Join SQL Right Join

SQL OPERATOR

SQL Comparison SQL LOGICAL Operator SQL Arithmetic

Difference

SQL vs NOSQL WHERE vs HAVING DELETE vs DROP GROUP BY vs ORDER BY DROP vs TRUNCATE SQL IN vs SQL EXISTS

MISC

SQL SubQuery SQL CASE Commit and Rollback in SQL Pattern Matching in SQL DDL Commands in SQL DML Commands in SQL Types of SQL Commands SQL COUNT SQL Primary Key SQL FOREIGN KEY SET Operators in SQL Check Constraint in SQL SQL EXCEPT SQL VIEW SQL WHERE Statement SQL CRUD Operation Where Condition in SQL TCL Commands in SQL Types of SQL JOINS SQL Nth Highest Salary SQL NOT OPERATOR SQL UNION ALL SQL INTERSECT SQL Data Definition Language SQL Data Manipulation Language SQL Data Control Language SQL CONSTRAINTS SQL KEYS Codd’s Rules in SQL What is SQL Injection? Trigger In SQL SQL WHERE Multiple Conditions Truncate function in SQL

How To

How to use the BETWEEN operator in SQL How To Use INNER JOIN In SQL How to use LIKE in SQL How to use HAVING Clause in SQL How to use GROUP BY Clause in SQL How To Remove Duplicates In SQL How To Delete A Row In SQL How to add column in table in SQL ? How to drop a column in SQL? How to create a database in SQL? How to use COUNT in SQL? How to Create Temporary Table in SQL? How to Add Foreign Key in SQL? How to Add Comments in SQL? How To Use Group By Clause In SQL How To Use Having Clause In SQL How To Delete Column In Table How To Compare Date In SQL

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



ADVERTISEMENT
ADVERTISEMENT