Div Function In Sql in SQL
? DIV Function in SQL
The DIV operator is used to perform integer division — it divides two numbers and returns the quotient without the remainder (i.e., the result is an integer).
? Syntax
expr1 DIV expr2expr1andexpr2are numeric expressions.The result is the integer part of the division.
? Example
SELECT 17 DIV 5; -- Result: 3Explanation: 17 divided by 5 is 3.4, but DIV returns only the integer part, 3.
? Notes
DIVis supported in MySQL and some other databases.In other SQL databases, you may use functions like
FLOOR(expr1 / expr2)orCAST(expr1 / expr2 AS INT)to achieve similar results.It differs from the regular division operator
/which returns a decimal or float value.
Equivalent in MySQL:
SELECT 17 DIV 5; -- 3SELECT 17 / 5; -- 3.4SELECT FLOOR(17 / 5); -- 3If you want, I can help you with integer division in other SQL dialects!