Loading

Mysql Arithmetic Operators Example

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 an 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

Share with:


Leave a Reply

Connect with:





z35W7z4v9z8w