MySQL Arithmetic Operators is used to perform mathematical operation like addition, subtraction, multiplication, division, etc.
Arithmetic Operators Example:-
Here I am putting a few examples, which will explain how Arithmetic operators are working in MySQL:- SELECT 5 + 7;
Result:- 12
SELECT 8 – 6;
Result:- 2
SELECT 5*4
Result 20
SELECT 5 MOD 3;
Result 2
SELECT 5 % 3;
Result 2
SELECT 5 / 3
Result:- 1.667
SELECT 5 DIV 3
Result:- 1
Suppose We have table “Stock”. It is only a rough example for real-time understanding:-
Id | product_name | unit_price | quantity |
1 | pen | 7 | 12 |
2 | pen | 7 | 5 |
SELECT (unit_price * quantity) AS total_price FROM `order` WHERE `product_name` = “pen”
total_price
84
35
SELECT Quantity + unit_price FROM `order` WHERE `product_name` = “pen”
quantity + unit_price
19
12
SELECT quantity DIV unit_price FROM `order` WHERE `product_name` = “pen”
quantity DIV unit_price
1
0
SELECT quantity / unit_price FROM `order` WHERE `product_name` = “pen”
quantity / unit_price
1.7142857142857142
0.7142857142857143
SELECT quantity % unit_price FROM `order` WHERE `product_name` = “pen”
quantity % unit_price
5
5
Read also:-
MySQL String Comparison Operator Functions
For more detail about operators please check the Manual