There are two division operators provided in SQL: / is used to calculate the floating point quotient, and DIV is used to calculate integer division, and the result is an integer. Watch out for floating-point results when using the / operator and divide-by-zero errors when using the DIV operator.
Division in SQL
There are two ways to express division in SQL:
1. /
(Division operator)
/
operator is used to calculate the quotient of two numbers. The result is a floating point number, even if both operands are integers.
For example:
<code class="sql">SELECT 10 / 3; -- 结果为 3.333333333333333</code>
2. DIV
(integer division operator)
DIV
operator Used to calculate the divisibility of two numbers and the result is an integer. If the divisor is 0, an error is returned.
For example:
<code class="sql">SELECT 10 DIV 3; -- 结果为 3</code>
Notes on choosing a division operator:
/
Operator. DIV
operator. DIV
operator with caution to avoid errors. The above is the detailed content of How to express division in sql. For more information, please follow other related articles on the PHP Chinese website!