MySQL Tutorial/Math Numeric Functions/MOD — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 09:49, 26 мая 2010

(MOD(4, 0)) will return a null value

mysql>
mysql> SELECT MOD(4, 0) as Result;
+--------+
| Result |
+--------+
|   NULL |
+--------+
1 row in set (0.00 sec)


MOD(N,0) returns NULL.

MOD() also works on values that have a fractional part and returns the exact remainder after division:



mysql>
mysql> SELECT MOD(34.5,3);
+-------------+
| MOD(34.5,3) |
+-------------+
|         1.5 |
+-------------+
1 row in set (0.00 sec)
mysql>


MOD(N,M), N % M, N MOD M: modulo operation. returns the remainder of N divided by M.

mysql>
mysql> SELECT MOD(234, 10);
+--------------+
| MOD(234, 10) |
+--------------+
|            4 |
+--------------+
1 row in set (0.02 sec)
mysql>
mysql> SELECT 253 % 7;
+---------+
| 253 % 7 |
+---------+
|       1 |
+---------+
1 row in set (0.00 sec)
mysql>
mysql> SELECT MOD(29,9);
+-----------+
| MOD(29,9) |
+-----------+
|         2 |
+-----------+
1 row in set (0.00 sec)
mysql>
mysql> SELECT 29 MOD 9;
+----------+
| 29 MOD 9 |
+----------+
|        2 |
+----------+
1 row in set (0.00 sec)
mysql>


The modulo function returns the remainder of two numbers.

mysql>
mysql>
mysql> SELECT MOD(14, 3) as Result;
+--------+
| Result |
+--------+
|      2 |
+--------+
1 row in set (0.00 sec)
mysql>