REMAINDER
Returns the remainder of expr1 divided by expr2.
All data types that can be converted to a numeric data type are accepted as arguments.
The REMAINDER function is very similar to the MOD function. The MOD function uses FLOOR in its formula, while REMAINDER uses the ROUND function, which can result in different return values.
Syntax
sql
REMAINDER(expr1, expr2)Usage Notes
- If either expr1 =
0or expr2 =infand the arguments are numeric, an error is returned. - If expr2 !=
0, the remainder is calculated asexpr1 - (expr2 * N), whereNis the integer closest to the quotient**expr1**/**expr2**. Nis rounded to the nearest even integer.- If expr1 is a
DECIMALand the remainder is0, the sign of the remainder is taken from the sign of expr1. - The remainder value of
0is returned without a sign.
Examples
sql
select remainder(5.23, 2),
mod(5.23, 2),
remainder(5, 2),
mod(5, 2);+--------------------+--------------+-----------------+-----------+
| REMAINDER(5.23, 2) | MOD(5.23, 2) | REMAINDER(5, 2) | MOD(5, 2) |
+--------------------+--------------+-----------------+-----------+
| -0.77 | 1.23 | 1 | 1 |
+--------------------+--------------+-----------------+-----------+