DIV
SQL construct
Divides one number by another and drops the fractional part of the result.
MySQL 8.1
dividend DIV divisorParameters
- dividendDECIMAL
- Dividend
- divisorDECIMAL
- Divisor
Return value
An integer; NULL when dividing by 0
Examples
Integer and regular division
MySQL 8.1
SELECT 7 DIV 2 AS quotient,
7 / 2 AS division,
7 % 2 AS remainder;Negative number: DIV and FLOOR
MySQL 8.1
SELECT -7 DIV 2 AS div_result,
FLOOR(-7 / 2) AS floor_result;Age rounded down to a decade
MySQL 8.1
SELECT member_name,
TIMESTAMPDIFF(YEAR, birthday, '2024-01-01') DIV 10 * 10 AS age_decade
FROM FamilyMembers;Details
DIV is an operator, not a function, so it is written between numbers without parentheses. The fractional part is dropped towards zero, not down: -7 DIV 2 returns -3, while FLOOR(-7 / 2) returns -4. The remainder of the same division is given by MOD or %. PostgreSQL has no such operator: integers are divided without remainder by the regular /, and for fractional numbers there is the DIV(a, b) function.