All pages
Powered by GitBook
1 of 6

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Addition Operator (+)

Syntax

+

Description

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.

Examples

See Also

This page is licensed: GPLv2, originally from

Operator Precedence
Type Conversion
Subtraction Operator (-)
Multiplication Operator (*)
Division Operator (/)
fill_help_tables.sql
SELECT 3+5;
+-----+
| 3+5 |
+-----+
|   8 |
+-----+

Arithmetic Operators

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 Operator (-)

Syntax

Description

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.

Examples

Unary minus:

See Also

This page is licensed: CC BY-SA / Gnu FDL

Division Operator (/)

Syntax

Description

Division operator. Dividing by zero will return NULL. By default, returns four digits after the decimal. This is determined by the server system variable

Modulo Operator (%)

Syntax

Description

Modulo operator. Returns the remainder of N divided by M

-
Operator Precedence
SQL_MODE
Type Conversion
Addition Operator (+)
Multiplication Operator (*)
Division Operator (/)
which by default is four. It can be set from 0 to 30.

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.

Examples

Changing div_precision_increment for the session from the default of four to six:

See Also

  • Type Conversion

  • Module operator (%)

  • Addition Operator (+)

  • Subtraction Operator (-)

This page is licensed: GPLv2, originally from fill_help_tables.sql

div_precision_increment
. See also
.

Examples

See Also

  • Operator Precedence

This page is licensed: GPLv2, originally from fill_help_tables.sql

N % M
MOD

Multiplication Operator (*)

Syntax

Description

Multiplication operator.

SELECT 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 |
+-----------+
Multiplication Operator (*)
truncate()
Operator Precedence
DIV function
Examples

See Also

  • Type Conversion

  • Addition Operator (+)

  • Subtraction Operator (-)

  • Division Operator (/)

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 |
+-------------------------------------+
Operator Precedence