MySQL Modulus refer to the remainder value obtained when a value 'a' is divided by 'b'.
Understand with Example
The Tutorial illustrate an example from 'MySQL Modulus'. To understand and elaborate the example we create a table 'oddeven' that has the required fieldnames and datatypes respectively.
Query for creating table named oddeven:
mysql> create table oddeven
-> (
-> a int(30),
-> b int(35));
Query OK, 0 rows affected (0.08 sec)
|
Query for inserting data into table named oddeven:
The insert into is used to add the records or rows in the table oddeven.
mysql> insert into oddeven
-> values
-> (11,23),(23,23),(24,23),(25,25),(62,27),(72,29);
Query OK, 6 rows affected (0.02 sec)
Records: 6 Duplicates: 0 Warnings: 0
|
Query for viewing data of table named oddeven:
mysql> select * from oddeven; +------+------+ | a | b | +------+------+ | 11 | 23 | | 23 | 23 | | 24 | 23 | | 25 | 25 | | 62 | 27 | | 72 | 29 | +------+------+ 6 rows in set (0.00 sec) |
Query for finding mod of the two fields from table named oddeven:
The Query b MOD a is used to return the remainder value as a result from table 'oddeven'. The below example returns remainder values as column name b mod a when the values in column b is divided by values in column a.
mysql> SELECT b MOD a from oddeven; +---------+ | b MOD a | +---------+ | 1 | | 0 | | 23 | | 0 | | 27 | | 29 | +---------+ 6 rows in set (0.00 sec) |
|
Recommend the tutorial |
Ask Questions? Discuss: MySQL Modulus
Post your Comment