SQL - Arithmetic operators
In SQL Server, arithmetic operators are used to perform mathematical operations on numeric values within SQL statements. The following arithmetic operators are available in SQL Server:
1-Addition (+): Adds two values together.
Example:
SELECT 5 + 3;
-- Output: 8
2-Subtraction (-): Subtracts one value from another.
Example:
SELECT 10 - 4;
-- Output: 6
3-Multiplication (*): Multiplies two values.
Example:
SELECT 6 * 3;
-- Output: 18
4-Division (/): Divides one value by another.
Example:
SELECT 15 / 5;
-- Output: 3
5-Modulo (%): Returns the remainder of a division operation.
Example:
SELECT 17 % 5;
-- Output: 2
It's important to note that these arithmetic operators can be used with numeric data types such as INT, FLOAT, DECIMAL, etc. They can be used in SELECT statements, WHERE clauses, or as part of calculations in SQL expressions.