The following table lists all arithmetic operators.
| Operator | Operand | Description |
|---|---|---|
+ |
Unary/Binary | The unary plus (+) indicates a positive number, and the binary plus is the addition operator. |
- |
Unary/Binary | The unary minus (-) indicates a negative number, and the binary minus is the subtraction operator. |
* |
Binary | The multiplication operator. |
/ |
Binary | The general division operator. |
DIV |
Binary | Returns the quotient of an integer division. |
MOD or % |
Binary | Returns the remainder of an integer division. |
Principles to be followed in integer divisions:
- The quotient is rounded off toward 0 regardless of whether the quotient is positive or negative.
- The positive/negative attribute of the remainder is the same as that of the dividend.
Example:
obclient> SELECT (-7) DIV (3.6), (-7) MOD (3.6);
+----------------+----------------+
| (-7) DIV (3.6) | (-7) MOD (3.6) |
+----------------+----------------+
| -1 | -3.4 |
+----------------+----------------+
1 row in set (0.01 sec)
obclient> SELECT (-7) DIV (-3.4), (-7) % (-3.4);
+-----------------+---------------+
| (-7) DIV (-3.4) | (-7) % (-3.4) |
+-----------------+---------------+
| 2 | -0.2 |
+-----------------+---------------+
1 row in set (0.02 sec)