Jump to: navigation, search

Mysql operator MOD

From w3cyberlearnings

Contents

MySQL MOD Function

This operator returns the remainder of N divided by M.

Syntax MOD

  • N the first number (dividend)
  • M the second number (divisor)
N MOD M

OR

N % M

Example 1

mysql> SELECT 43 % 10;
+---------+
| 43 % 10 |
+---------+
|       3 | 
+---------+
1 row in set (0.00 sec)

mysql> SELECT 43 MOD 10;
+-----------+
| 43 MOD 10 |
+-----------+
|         3 | 
+-----------+
1 row in set (0.00 sec)

Example 2


mysql> SELECT * FROM totalearn;
+----+------------+-------------+
| id | total_hour | hourly_rate |
+----+------------+-------------+
|  1 |         30 |          50 | 
|  2 |         40 |          50 | 
|  3 |         30 |          80 | 
|  4 |         34 |          90 | 
+----+------------+-------------+
4 rows in set (0.00 sec)

mysql> SELECT id,
    -> total_hour,
    -> hourly_rate % 40 as hourly_mod_40
    -> FROM totalearn;
+----+------------+---------------+
| id | total_hour | hourly_mod_40 |
+----+------------+---------------+
|  1 |         30 |            10 | 
|  2 |         40 |            10 | 
|  3 |         30 |             0 | 
|  4 |         34 |            10 | 
+----+------------+---------------+
4 rows in set (0.00 sec)


Related Links

# Function Description
1 DIV Integer division
2 / Division operator
3 - Minus operator
4 % or MOD Modulo operator
5 + Addition operator
6 * Multiplication operator
7 - Change the sign of the argument
Navigation
Web
SQL
MISC
References