Function Reference

DIV

SQL construct

Divides one number by another and drops the fractional part of the result.

MySQL 8.1
dividend DIV divisor

Parameters

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;
quotientdivisionremainder
33.51

Negative number: DIV and FLOOR

MySQL 8.1
SELECT -7 DIV 2 AS div_result,
	FLOOR(-7 / 2) AS floor_result;
div_resultfloor_result
-3-4

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;
member_nameage_decade
Headley Quincey60
Flavia Quincey60
Andie Quincey40
Lela Quincey30
Annie Quincey30
Ernest Forrest60
Constance Forrest50
Wednesday Addams10

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.

See also

Where to learn