The MOD function returns the remainder of the first parameter m divided by the second parameter n. If n is 0, m is returned without the division operation being performed.
Note that if the dividend, the parameter m of the MOD function, is a negative number, the function operates differently from a typical operation (classical modulus) method.
Result of MOD
m |
n |
MOD(m, n) |
Classical Modulus |
---|---|---|---|
11 |
4 |
3 |
3 |
11 |
-4 |
3 |
-1 |
-11 |
4 |
-3 |
1 |
-11 |
-4 |
-3 |
-3 |
11 |
0 |
11 |
Divided by 0 error |
MOD(m, n)
--it returns the reminder of m divided by n
SELECT MOD(11, 4), MOD(11, -4), MOD(-11, 4), MOD(-11, -4), MOD(11,0);
mod(11, 4) mod(11, -4) mod(-11, 4) mod(-11, -4) mod(11, 0)
=====================================================================
3 3 -3 -3 11
SELECT MOD(11.0, 4), MOD(11.000, 4), MOD(11, 4.0), MOD(11, 4.000);
mod(11.0, 4) mod(11.000, 4) mod(11, 4.0) mod(11, 4.000)
=========================================================================
3.0 3.000 3.0 3.000