|
|
Arithmetic operators perform basic mathematical calculations. If any of the values are null, the results of the entire operation are also usually null. For purposes of the calculation, strings are converted to numbers. Some strings are converted to the equivalent number (such as the strings '1' and '33'), but others are converted to 0 (such as the strings 'one' and 'abc').
value1 + value2
Adds two values together.
For example:
mysql> SELECT 1+3; +-----+ | 1+3 | +-----+ | 4 | +-----+ mysql> SELECT 15+"9"; +--------+ | 15+"9" | +--------+ | 24 | +--------+
value1 - value2
Subtracts value2 from value1.
For example:
mysql> SELECT 1-9; +-----+ | 1-9 | +-----+ | -8 | +-----+
value1 * value2
Multiplies two values with each other.
For example:
mysql> SELECT 12 * 10; +---------+ | 12 * 10 | +---------+ | 120 | +---------+
value1 / value2
Divides value1 by value2.
For example:
mysql> SELECT 4/2; +------+ | 4/2 | +------+ | 2.00 | +------+ mysql> SELECT 10005.00000/10004.00000; +-------------------------+ | 10005.00000/10004.00000 | +-------------------------+ | 1.0001000 | +-------------------------+
Returns the modulus (remainder after value1 is divided by value2).
For example:
mysql> SELECT 3%2; +------+ | 3%2 | +------+ | 1 | +------+
|
|