Mysql Mod

Incase you use MOD(a, 3) you get 1 for even numbers and 0 for odd numbers.


 
Ads

Mysql Mod

     

Mysql Mod (a,b) is performed to return remainder  when b is divided by a.

Incase you use MOD(a, 3) you get 1 for even numbers and 0 for odd numbers.

If you use MOD(a, 2) you get the last digit of the number a.

Understand with Example

The Tutorial illustrate an example from Mysql Mod. To understand and grasp the example we create a table oddeven with 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 Query insert into is used to add the records or rows to 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 used below is used to return the mode value as  remainder when b is divided by a.

mysql> SELECT b MOD a from oddeven;
+---------+
| b MOD a |
+---------+
|       1 |
|       0 |
|      23 |
|       0 |
|      27 |
|      29 |
+---------+
6 rows in set (0.00 sec)

Advertisements

Ads
Share on Google+Share on Google+

Mysql Mod

Posted on: January 24, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Mysql Mod  

Post your Comment


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

Ads

 

Ads