Arithmetic Operators operate on one or more numeric operands and returns a numeric output.
Following are the arithmetic operators.
Operator Description Syntax Example Output
+ Addition expression1 + expression2 20 + 10 30
- Subtraction expression1 - expression2 20 - 10 10
* Multiplication expression1 * expression2 20 * 10 200
/ Division. Expression on the left is the dividend and expression on the right is the divisor. dividend / divisor 20 / 10 2
% Modulo. Expression on the left is the dividend and expression on the right is the divisor. Output is the remainder of the division. dividend % divisor 20 % 8 4
Table: Product
ProductID ProductName Price
1 HD TV 1000
2 Play Station 400
3 MacBook 2000
4 IMAC 1500
5 IPOD 200
6 XBOX 500
7 MODEM 100
8 Nintendo 200
9 Speakers 100
10 Printer 200
11 SLR Camera 1000
12 Tablet 600
Example
Query :
SELECT ProductID, ProductName, Price,
Price + 10 AS 'Addition',
Price - 10 AS 'Subtraction',
Price * 10 AS 'Multiplication',
Price / 15 AS 'Division',
Price % 7 AS 'Modulo'
FROM Product
Output :
ProductID ProductName Price Addition Subtraction Multiplication Division Modulo
1 HD TV 1000 1010 990 10000 66 6
2 Play Station 400 410 390 4000 26 1
3 MacBook 2000 2010 1990 20000 133 5
4 IMAC 1500 1510 1490 15000 100 2
5 IPOD 200 210 190 2000 13 4
6 XBOX 500 510 490 5000 33 3
7 MODEM 100 110 90 1000 6 2
8 Nintendo 200 210 190 2000 13 4
9 Speakers 100 110 90 1000 6 2
10 Printer 200 210 190 2000 13 4
11 SLR Camera 1000 1010 990 10000 66 6
12 Tablet 600 610 590 6000 40 5
Description :
Here Addition, Subtraction and Multiplication columns are self-explanatory. Division column returns back the quotient when the Price (dividend) is divided by 15 (divisor). It truncates the fractional part of the quotient. Modulo column returns back the reminder when the Price (dividend) is divided by 7 (divisor).