+Addition.
If both operands are integers, the result is calculated with BIGINT precision. If either integer is unsigned, the result is also an unsigned integer.
For real or string operands, the operand with the highest precision determines the result precision.
This page is licensed: GPLv2, originally from
SELECT 3+5;
+-----+
| 3+5 |
+-----+
| 8 |
+-----+Learn about arithmetic operators in MariaDB Server SQL. This section details how to perform mathematical calculations like addition, subtraction, multiplication, and division within your queries.
Subtraction. The operator is also used as the unary minus for changing sign.
If both operands are integers, the result is calculated with BIGINT precision. If either integer is unsigned, the result is also an unsigned integer, unless the NO_UNSIGNED_SUBTRACTION is enabled, in which case the result is always signed.
For real or string operands, the operand with the highest precision determines the result precision.
Unary minus:
This page is licensed: CC BY-SA / Gnu FDL
-Dividing by zero returns NULL. If the default ERROR_ON_DIVISION_BY_ZERO SQL_MODE is used, a division by zero also produces a warning.
Changing div_precision_increment for the session from the default of four to six:
This page is licensed: GPLv2, originally from fill_help_tables.sql
This page is licensed: GPLv2, originally from fill_help_tables.sql
N % MSELECT 96-9;
+------+
| 96-9 |
+------+
| 87 |
+------+
SELECT 15-17;
+-------+
| 15-17 |
+-------+
| -2 |
+-------+
SELECT 3.66 + 1.333;
+--------------+
| 3.66 + 1.333 |
+--------------+
| 4.993 |
+--------------+SELECT - (3+5);
+---------+
| - (3+5) |
+---------+
| -8 |
+---------+/SELECT 4/5;
+--------+
| 4/5 |
+--------+
| 0.8000 |
+--------+
SELECT 300/(2-2);
+-----------+
| 300/(2-2) |
+-----------+
| NULL |
+-----------+
SELECT 300/7;
+---------+
| 300/7 |
+---------+
| 42.8571 |
+---------+SET div_precision_increment = 6;
SELECT 300/7;
+-----------+
| 300/7 |
+-----------+
| 42.857143 |
+-----------+
SELECT 300/7;
+-----------+
| 300/7 |
+-----------+
| 42.857143 |
+-----------+SELECT 1042 % 50;
+-----------+
| 1042 % 50 |
+-----------+
| 42 |
+-----------+This page is licensed: GPLv2, originally from fill_help_tables.sql
*SELECT 7*6;
+-----+
| 7*6 |
+-----+
| 42 |
+-----+
SELECT 1234567890*9876543210;
+-----------------------+
| 1234567890*9876543210 |
+-----------------------+
| -6253480962446024716 |
+-----------------------+
SELECT 18014398509481984*18014398509481984.0;
+---------------------------------------+
| 18014398509481984*18014398509481984.0 |
+---------------------------------------+
| 324518553658426726783156020576256.0 |
+---------------------------------------+
SELECT 18014398509481984*18014398509481984;
+-------------------------------------+
| 18014398509481984*18014398509481984 |
+-------------------------------------+
| 0 |
+-------------------------------------+