Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Sql Mysql-example MySQL Modulus

Related Tutorials


 
 

Share on Google+Share on Google+

MySQL Modulus

Advertisement
MySQL Modulus refer to the remainder value obtained when a value 'a' is divided by 'b'.

MySQL Modulus

     

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)
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 24, 2009

Related Tutorials

Discuss: MySQL Modulus  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com