Table 11.11 Arithmetic Operators
The usual arithmetic operators are available. The precision of the result is determined according to the following rules:
If both operands are integers and any of them are unsigned,
the result is an unsigned integer. For subtraction, if the
SQL mode is enabled, the result is signed even if any
operand is unsigned.
These rules are applied for each operation, such that nested
calculations imply the precision of each component. Hence,
(14620 / 9432456) / (24250 / 9432456),
resolves first to
(0.0014) / (0.0026), with
the final result having 8 decimal places
Because of these rules and the way they are applied, care should be taken to ensure that components and subcomponents of a calculation use the appropriate level of precision. See Section 11.10, “Cast Functions and Operators”.
For information about handling of overflow in numeric expression evaluation, see Section 10.2.5, “Out-of-Range and Overflow Handling”.
Arithmetic operators apply to numbers. For other types of
values, alternative operations may be available. For example, to
add date values, use
see Section 11.7, “Date and Time Functions”.
SELECT 3+5;-> 8
SELECT 3-5;-> -2
Unary minus. This operator changes the sign of the operand.
SELECT - 2;-> -2
SELECT 3*5;-> 15 mysql>
SELECT 18014398509481984*18014398509481984.0;-> 324518553658426726783156020576256.0
SELECT 3/5;-> 0.60
Division by zero produces a
SELECT 102/(1-1);-> NULL
A division is calculated with
BIGINT arithmetic only if
performed in a context where its result is converted to an
SELECT 5 DIV 2;-> 2
DIV was implemented in MySQL