MySQL DIV Operator
The DIV operator in MySQL performs integer division. Unlike the standard division operator (/), which returns a floating-point result, DIV returns only the integer part of the division, discarding any remainder.
DIV: Definition and Usage
DIV is particularly useful when you only need the whole-number result of a division and don't need the fractional part. This is common in scenarios where you're dealing with counts, quantities, or other values where fractional results don't make sense.
Syntax
Syntax
x DIV y
Parameter Values
| Parameter | Description |
|---|---|
x |
The dividend (the number being divided). This is required. |
y |
The divisor (the number by which you're dividing). This is required. |
Examples
Integer Division (10 divided by 5)
A simple example of integer division.
Syntax
SELECT 10 DIV 5;
Output
2
Integer Division (8 divided by 3)
This example shows that the remainder is discarded.
Syntax
SELECT 8 DIV 3;
Output
2