Numeric functions (Rounding and Truncation)
Returns the remainder of input expr1
divided by input expr2
.
Equivalent to the modulo arithmetic operator (for example, expr1 % expr2
).
expr1
A numeric expression.
expr2
A numeric expression.
Returns either an integer or a fixed-point decimal number.
Usage notes¶Both expr1
and expr2
must be numeric expressions. They aren’t required to be integers.
The returned value is the remainder from truncation-based division (rounding towards zero), not floor-based division (rounding down). Therefore, if expr1
is negative, the returned value is negative. This behavior is different from some programming languages (such as Python), but consistent with standard SQL. For more information, see the Modulo Wikipedia page.
The following example shows usage of the MOD()
function on both integer and non-integer values:
SELECT MOD(3, 2) AS mod1, MOD(4.5, 1.2) AS mod2;Copy
Output:
+------+------+ | MOD1 | MOD2 | +------+------+ | 1 | 0.9 | +------+------+Copy
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4