DIV
Operator Description
The DIV operator is used for integer division.
If both operand values are non-integer types, the operand values are converted to DECIMAL and the division is performed using the DECIMAL algorithm before converting the result to BIGINT. An error occurs if the result is outside the BIGINT range.
Grammar Structure
> SELECT value1 DIV value2;
> SELECT column1 DIV column2... FROM table_name;
Example
mysql> SELECT 5 DIV 2, -5 DIV 2, 5 DIV -2, -5 DIV -2;
+------------------------------------------------------------------------------------------------------------------------------
| 5 div 2 | -5 div 2 | 5 div -2 | -5 div -2 |
+------------------------------------------------------------------------------------------------------------------------------
| 2 | -2 | -2 | 2 |
+------------------------------------------------------------------------------------------------------------------------------
1 row in set (0.00 sec)
create table t2(c1 int, c2 int);
insert into t2 values (-3, 2);
insert into t2 values (1, 2);
mysql> select c1 DIV 3 from t2;
+-------------+
| c1 div 3 |
+-------------+
| -1 |
| 0 |
+-------------+
2 rows in set (0.00 sec)
mysql> select c1 DIV c2 from t2;
+---------------+
| c1 div c2 |
+---------------+
| -1 |
| 0 |
+---------------+
2 rows in set (0.00 sec)