### 12.6.1 Arithmetic Operators

[]()

[]()

**Table 12.9 Arithmetic Operators**

|                        Name                         |          Description           |
|-----------------------------------------------------|--------------------------------|
|[`%`, `MOD`](arithmetic-functions.html#operator_mod) |         Modulo operator        |
|   [`*`](arithmetic-functions.html#operator_times)   |     Multiplication operator    |
|   [`+`](arithmetic-functions.html#operator_plus)    |        Addition operator       |
|   [`-`](arithmetic-functions.html#operator_minus)   |         Minus operator         |
|[`-`](arithmetic-functions.html#operator_unary-minus)| Change the sign of the argument|
|  [`/`](arithmetic-functions.html#operator_divide)   |        Division operator       |
|   [`DIV`](arithmetic-functions.html#operator_div)   |        Integer division        |

 The usual arithmetic operators are available. The result is determined according to the following rules:

* In the case of [`-`](arithmetic-functions.html#operator_minus), [`+`](arithmetic-functions.html#operator_plus), and [`*`](arithmetic-functions.html#operator_times), the result is calculated with [`BIGINT`](integer-types.html) (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_SUBTRACTION`](sql-mode.html#sqlmode_no_unsigned_subtraction) SQL mode is enabled, the result is signed even if any operand is unsigned.

* If any of the operands of a [`+`](arithmetic-functions.html#operator_plus), [`-`](arithmetic-functions.html#operator_minus), [`/`](arithmetic-functions.html#operator_divide), [`*`](arithmetic-functions.html#operator_times), [`%`](arithmetic-functions.html#operator_mod) 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 [`/`](arithmetic-functions.html#operator_divide), the scale of the result when using two exact-value operands is the scale of the first operand plus the value of the [`div_precision_increment`](server-system-variables.html#sysvar_div_precision_increment) system variable (which is 4 by default). For example, the result of the expression `5.05 / 0.014` has 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. See [Section 12.11, “Cast Functions and Operators”](cast-functions.html).

 For information about handling of overflow in numeric expression evaluation, see [Section 11.1.7, “Out-of-Range and Overflow Handling”](out-of-range-and-overflow.html).

 Arithmetic operators apply to numbers. For other types of values, alternative operations may be available. For example, to add date values, use [`DATE_ADD()`](date-and-time-functions.html#function_date-add); see [Section 12.7, “Date and Time Functions”](date-and-time-functions.html).

[]()[]()

* []()

  [`+`](arithmetic-functions.html#operator_plus)

  []()[]()

   Addition:

  ```
  mysql> SELECT 3+5;
          -> 8
  ```

* []()

  [`-`](arithmetic-functions.html#operator_minus)

  []()[]()

   Subtraction:

  ```
  mysql> SELECT 3-5;
          -> -2
  ```

* []()

  [`-`](arithmetic-functions.html#operator_unary-minus)

  []()[]()[]()

   Unary minus. This operator changes the sign of the operand.

  ```
  mysql> SELECT - 2;
          -> -2
  ```

  Note

   If this operator is used with a [`BIGINT`](integer-types.html), the return value is also a [`BIGINT`](integer-types.html). This means that you should avoid using `-` on integers that may have the value of −2<sup>63</sup>.

* []()

  [`*`](arithmetic-functions.html#operator_times)

  []()[]()

   Multiplication:

  ```
  mysql> SELECT 3*5;
          -> 15
  mysql> SELECT 18014398509481984*18014398509481984.0;
          -> 324518553658426726783156020576256.0
  mysql> SELECT 18014398509481984*18014398509481984;
          -> out-of-range error
  ```

   The last expression produces an error because the result of the integer multiplication exceeds the 64-bit range of [`BIGINT`](integer-types.html) calculations. (See [Section 11.1, “Numeric Data Types”](numeric-types.html).)

* []()

  [`/`](arithmetic-functions.html#operator_divide)

  []()[]()

   Division:

  ```
  mysql> SELECT 3/5;
          -> 0.60
  ```

   Division by zero produces a `NULL` result:

  ```
  mysql> SELECT 102/(1-1);
          -> NULL
  ```

   A division is calculated with [`BIGINT`](integer-types.html) arithmetic only if performed in a context where its result is converted to an integer.

* []()

  [`DIV`](arithmetic-functions.html#operator_div)

  []()

   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 [`DECIMAL`](fixed-point-types.html) and divided using [`DECIMAL`](fixed-point-types.html) arithmetic before converting the result to [`BIGINT`](integer-types.html). If the result exceeds `BIGINT` range, an error occurs.

  ```
  mysql> SELECT 5 DIV 2, -5 DIV 2, 5 DIV -2, -5 DIV -2;
          -> 2, -2, -2, 2
  ```

* []()

  [`*`N`* % *`M`*`](arithmetic-functions.html#operator_mod), [`*`N`* MOD *`M`*`](arithmetic-functions.html#operator_mod)

  []()

   Modulo operation. Returns the remainder of *`N`* divided by *`M`*. For more information, see the description for the [`MOD()`](mathematical-functions.html#function_mod) function in [Section 12.6.2, “Mathematical Functions”](mathematical-functions.html).

