Preloader

SQL Arithmetic Operators

SQL
SQL Tutorials

SQL arithmetic operators allow you to perform basic mathematical calculations in queries. You commonly use them when working with numeric columns such as salary, price, quantity, or marks. These operators help calculate totals, differences, averages, and percentages directly inside SQL statements.

List of SQL Arithmetic Operators

OperatorDescription
+Adds two values
-Subtracts one value from another
*Multiplies values
/Divides one value by another
%Returns the remainder after division

Addition Operator (+)

The addition operator adds two or more numeric values.

Example

Calculate total salary by adding bonus to salary.

SELECT salary + bonus AS total_salary
FROM employees;

This query returns the final salary including the bonus for each employee.

Subtraction Operator (-)

The subtraction operator finds the difference between two values.

Example

Calculate remaining stock after sales.

SELECT total_stock - sold_stock AS remaining_stock
FROM products;

This helps track inventory more accurately.

Multiplication Operator (*)

The multiplication operator multiplies numeric values.

Example

Calculate total price based on quantity.

SELECT price * quantity AS total_price
FROM orders;

This is useful when generating bills or invoices.

Division Operator (/)

The division operator divides one number by another.

Example

Calculate average marks.

SELECT total_marks / total_subjects AS average_marks
FROM students;

Always make sure the divisor is not zero to avoid errors.

Modulus Operator (%)

The modulus operator returns the remainder after division.

Example

Check even or odd numbers.

SELECT number % 2 AS remainder
FROM numbers;

If the remainder is 0, the number is even.

Using Arithmetic Operators with WHERE Clause

You can also use arithmetic operators inside conditions.

Example

SELECT *
FROM employees
WHERE salary * 12 > 500000;

This query filters employees whose yearly salary exceeds 500000.

Using Arithmetic Operators with SELECT and Aliases

You can rename calculated columns using aliases for better readability.

SELECT price * quantity AS total_amount
FROM sales;

Aliases make query results easier to understand.

Important Points to Remember

  • Arithmetic operators work only with numeric data types.
  • Division by zero causes an error, so handle it carefully.
  • Use aliases to label calculated results clearly.
  • Arithmetic operations execute before comparison operators.

When to Use SQL Arithmetic Operators

  • Calculating salaries, discounts, and taxes
  • Generating invoices and totals
  • Performing data analysis
  • Filtering records based on calculated values

Check out our resources!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *