AnalyticDB for MySQL supports the following arithmetic operators for numeric calculations on constants and columns.
| Operator | Syntax | Description |
|---|---|---|
+ | a + b | Addition |
- | a - b | Subtraction |
* | a * b | Multiplication |
/ | a / b | Division |
DIV | a DIV b | Integer division — divides a by b and returns a truncated integer |
% or MOD | a % b or a MOD b | Modulo — returns the remainder of a divided by b |
- (unary) | -a | Negation — changes the sign of a |
+
Adds two numeric expressions.
SELECT 3 + 5; -- 8
SELECT 3 + 2.9875; -- 5.9875-
Subtracts one numeric expression from another.
SELECT 3 - 5; -- -2
SELECT 3 - 1.5; -- 1.5*
Multiplies two numeric expressions.
SELECT 3 * pi(); -- 9.42477796076938/
Divides one numeric expression by another.
SELECT 3 / pi(); -- 0.954929658551372DIV
Divides one integer expression by another and returns a truncated integer result.
SELECT 3 DIV pi(); -- 0
SELECT 33 DIV 2; -- 16% or MOD
Returns the remainder of one numeric expression divided by another. % and MOD are equivalent.
SELECT 3 MOD pi(); -- 3.0
SELECT 33 % 2; -- 1- (unary)
Changes the sign of a numeric expression — converts a positive number to negative, or a negative number to positive.
SELECT -2; -- -2
SELECT --2; -- 2