0% found this document useful (0 votes)
2 views

Arithmetic_Operators_SQL

Arithmetic operators in SQL allow for mathematical operations on numerical data types, including addition, subtraction, multiplication, division, and modulus. The document provides examples of how to use these operators in SQL queries with a sample employees table. It emphasizes the importance of using these operators carefully, particularly with division to avoid errors.

Uploaded by

Vijaya kumari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Arithmetic_Operators_SQL

Arithmetic operators in SQL allow for mathematical operations on numerical data types, including addition, subtraction, multiplication, division, and modulus. The document provides examples of how to use these operators in SQL queries with a sample employees table. It emphasizes the importance of using these operators carefully, particularly with division to avoid errors.

Uploaded by

Vijaya kumari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Arithmetic Operators in SQL

1. Introduction

Arithmetic operators in SQL are used to perform mathematical operations on numerical data types.

These operations can be performed on columns, constants, or expressions.

2. List of Arithmetic Operators

Operator | Description | Example

-----------|-------------------------|-----------------

+ | Addition | 10 + 5 = 15

- | Subtraction | 10 - 5 = 5

* | Multiplication | 10 * 5 = 50

/ | Division | 10 / 5 = 2

% | Modulus (Remainder) | 10 % 3 = 1

3. Syntax

SELECT column_name, column_name OPERATOR value

FROM table_name;

4. Example Table: employees

emp_id | emp_name | salary

---------|----------|---------

1 | Alice | 30000

2 | Bob | 45000

3 | Carol | 50000

5. Examples with SQL Queries

1. Addition (+)

SELECT emp_name, salary, salary + 5000 AS new_salary


FROM employees;

Increases each employee's salary by 5000.

2. Subtraction (-)

SELECT emp_name, salary, salary - 2000 AS reduced_salary

FROM employees;

Reduces each employee's salary by 2000.

3. Multiplication (*)

SELECT emp_name, salary, salary * 1.1 AS increased_salary

FROM employees;

Increases salary by 10%.

4. Division (/)

SELECT emp_name, salary, salary / 2 AS half_salary

FROM employees;

Calculates half of the salary.

5. Modulus (%)

SELECT emp_name, salary, salary % 1000 AS remainder

FROM employees;

Finds the remainder when salary is divided by 1000.

6. Conclusion

- Arithmetic operators in SQL help perform mathematical calculations.

- They can be used in SELECT, WHERE, HAVING, and other SQL clauses.

- Be careful with division (/), as dividing by zero causes an error.

You might also like