MySQL Arithmetic

Arithmetic operators are used to perform mathematical operations on two expressions to negate, add, subtract, multiply, and divide numeric values.

Ads

MySQL Arithmetic

     

This example illustrates how to use arithmetic operator in the MySQL.

Arithmetic operators are used to perform mathematical operations on two expressions to negate, add, subtract, multiply, and divide numeric values. In this example we use arithmetic operators +, /, -, * and  %.

 

 

 

 

SQL Arithmetic Operators:

Operator
Definition
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Modulus

Examples:

Query
Output
select 3+5;
+-----+
| 3+5 |
+-----+
| 8   |
+-----+
select 5/3;
+--------+
| 5/3    |
+--------+
| 1.6667 |
+--------+
select 3-5;
+-----+
| 3-5 |
+-----+
| -2  |
+-----+
select 3%5;
+-----+
| 3%5 |
+-----+
| 3   |
+-----+
select 20%5;
+------+
| 20%5 |
+------+
| 0    |
+------+
select 3*5;
+-----+
| 3*5 |
+-----+
| 15  |
+-----+

Advertisements

Ads
Share on Google+Share on Google+

MySQL Arithmetic

Posted on: October 6, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: MySQL Arithmetic  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads