Jump to: navigation, search

Mysql operator DIV

From w3cyberlearnings

Contents

MySQL DIV operator Function

This operator divides two numbers and returns result.

Syntax DIV

  • N1 the first number (dividend)
  • N2 the second number (divisor)
N1 DIV N2

Example 1

mysql> SELECT 15 DIV 3;
+----------+
| 15 DIV 3 |
+----------+
|        5 | 
+----------+
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/3)+hourly_rate as plus
    -> FROM totalearn;
+----+------------+------------------+
| id | total_hour | plus             |
+----+------------+------------------+
|  1 |         30 | 66.6666666666667 | 
|  2 |         40 | 66.6666666666667 | 
|  3 |         30 | 106.666666666667 | 
|  4 |         34 |              120 | 
+----+------------+------------------+
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