DIV
This page is part of MariaDB's Documentation.
The parent of this page is: SQL Operators for MariaDB Xpand
Topics on this page:
Overview
Integer division.
USAGE
dividend DIV divisor
Value Name | Description |
---|---|
| The numbers in the division |
| The numbers in the division |
DETAILS
The DIV
operator divides the dividend by the divisor and returns the integer result of the division with any decimal places truncated from the value. The DIV
operator is similar to the DIVINT()
function.
A NULL
is returned if the divisor is 0 or if either the dividend or divisor is NULL
.
Because the returned value is not rounded down, the result of x DIV y
is not the same as FLOOR(x DIV y)
when the resulting value is negative.
To obtain the floating point result of a division operation, see "/" or "DIVFLT()".
EXAMPLES
SELECT 12345 DIV 10, 22 DIV 3, .5 DIV .25;
+--------------+----------+------------+
| 12345 DIV 10 | 22 DIV 3 | .5 DIV .25 |
+--------------+----------+------------+
| 1234 | 7 | 2 |
+--------------+----------+------------+
CREATE TABLE div_example (
val INT
);
INSERT INTO div_example VALUES
(21), (22), (23), (24), (25), (26), (27), (28),
(-21), (-22), (-23), (-24), (-25), (-26), (-27), (-28);
SELECT val, val DIV 7, val / 7, FLOOR(val / 7)
FROM div_example;
+------+-----------+---------+----------------+
| val | val DIV 7 | val / 7 | FLOOR(val / 7) |
+------+-----------+---------+----------------+
| 21 | 3 | 3.0000 | 3 |
| 22 | 3 | 3.1429 | 3 |
| 23 | 3 | 3.2857 | 3 |
| 24 | 3 | 3.4286 | 3 |
| 25 | 3 | 3.5714 | 3 |
| 26 | 3 | 3.7143 | 3 |
| 27 | 3 | 3.8571 | 3 |
| 28 | 4 | 4.0000 | 4 |
| -21 | -3 | -3.0000 | -3 |
| -22 | -3 | -3.1429 | -4 |
| -23 | -3 | -3.2857 | -4 |
| -24 | -3 | -3.4286 | -4 |
| -25 | -3 | -3.5714 | -4 |
| -26 | -3 | -3.7143 | -4 |
| -27 | -3 | -3.8571 | -4 |
| -28 | -4 | -4.0000 | -4 |
+------+-----------+---------+----------------+