PDF (A4) - 35.2Mb
Man Pages (TGZ) - 256.4Kb
Man Pages (Zip) - 361.2Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
MySQL Globalization
MySQL Information Schema
MySQL Installation Guide
MySQL and Linux/Unix
MySQL and macOS
MySQL Partitioning
MySQL Performance Schema
MySQL Replication
Using the MySQL Yum Repository
MySQL Restrictions and Limitations
Security in MySQL
MySQL and Solaris
Building MySQL from Source
Starting and Stopping MySQL
MySQL Tutorial
MySQL and Windows
MySQL NDB Cluster 7.5
The usual arithmetic operators are available. The result is determined according to the following rules:
In the case of
-,+, and*, the result is calculated withBIGINT(64-bit) precision if both operands are integers.If both operands are integers and any of them are unsigned, the result is an unsigned integer. For subtraction, if the
NO_UNSIGNED_SUBTRACTIONSQL mode is enabled, the result is signed even if any operand is unsigned.If any of the operands of a
+,-,/,*,%is a real or string value, the precision of the result is the precision of the operand with the maximum precision.In division performed with
/, the scale of the result when using two exact-value operands is the scale of the first operand plus the value of thediv_precision_incrementsystem variable (which is 4 by default). For example, the result of the expression5.05 / 0.014has a scale of six decimal places (360.714286).
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 (0.60288653).
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. SeeSection 12.10, “Cast Functions and Operators”.
For information about handling of overflow in numeric expression evaluation, seeSection 11.1.7, “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, useDATE_ADD(); seeSection 12.7, “Date and Time Functions”.
Addition:
mysql> SELECT 3+5; -> 8Subtraction:
mysql> SELECT 3-5; -> -2Unary minus. This operator changes the sign of the operand.
mysql> SELECT - 2; -> -2Multiplication:
mysql> SELECT 3*5; -> 15mysql> SELECT 18014398509481984*18014398509481984.0; -> 324518553658426726783156020576256.0mysql> SELECT 18014398509481984*18014398509481984; -> out-of-range errorThe last expression produces an error because the result of the integer multiplication exceeds the 64-bit range of
BIGINTcalculations. (SeeSection 11.1, “Numeric Data Types”.)Division:
mysql> SELECT 3/5; -> 0.60Division by zero produces a
NULLresult:mysql> SELECT 102/(1-1); -> NULLA division is calculated with
BIGINTarithmetic only if performed in a context where its result is converted to an integer.Integer division. Discards from the division result any fractional part to the right of the decimal point.
If either operand has a noninteger type, the operands are converted to
DECIMALand divided usingDECIMALarithmetic before converting the result toBIGINT. If the result exceedsBIGINTrange, an error occurs.mysql> SELECT 5 DIV 2, -5 DIV 2, 5 DIV -2, -5 DIV -2; -> 2, -2, -2, 2Modulo operation. Returns the remainder of
Ndivided byM. For more information, see the description for theMOD()function inSection 12.6.2, “Mathematical Functions”.
PDF (A4) - 35.2Mb
Man Pages (TGZ) - 256.4Kb
Man Pages (Zip) - 361.2Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
MySQL Globalization
MySQL Information Schema
MySQL Installation Guide
MySQL and Linux/Unix
MySQL and macOS
MySQL Partitioning
MySQL Performance Schema
MySQL Replication
Using the MySQL Yum Repository
MySQL Restrictions and Limitations
Security in MySQL
MySQL and Solaris
Building MySQL from Source
Starting and Stopping MySQL
MySQL Tutorial
MySQL and Windows
MySQL NDB Cluster 7.5