SQL Airthmetic Operators
In SQL, operators are special keywords or symbols used to perform operations on data stored in relational databases.
Output:
Types of SQL Operators
Student Table
Example: SQL Query to Add Marks
- Arithmetic Operators – Perform mathematical operations
- Comparison Operators – Compare values (=, >, <, etc.)
- Logical Operators – Combine multiple conditions (AND, OR, NOT)
- Set Operators – Combine result sets (UNION, INTERSECT)
- Unary Operators – Work with a single operand (IS NULL, IS NOT NULL)
- Bitwise Operators – Perform bit-level operations (&, |, ^, etc.)
SQL Arithmetic Operators
These operators are used to perform basic mathematical operations on numeric values in SQL tables.
These operators are used to perform basic mathematical operations on numeric values in SQL tables.
Operator | Description |
---|---|
+ | Addition - Adds two values |
- | Subtraction - Subtracts one value from another |
* | Multiplication - Multiplies values |
/ | Division - Divides one value by another |
% | Modulus - Returns the remainder after division |
Student Table
ID | Physics | Chemistry |
---|---|---|
101 | 86 | 92 |
102 | 85 | 91 |
103 | 73 | 98 |
Example: SQL Query to Add Marks
SELECT Physics + Chemistry AS Total_Marks
FROM student;
Output:
Total_Marks |
---|
178 |
176 |
171 |
Explanation:
This query adds the values in the Physics and Chemistry columns for each student and returns it as Total_Marks.
Key Point
- SQL arithmetic operators work directly within SELECT statements.
- You can also use them in UPDATE queries to compute new values.
- Useful for generating derived/calculated columns on the fly.