您的位置:首页 > 数据库 > MySQL

MySQL数学函数之div的用法

2018-03-12 20:16 926 查看

语法

DIV

Integer division. Discards from the division result any fractional part to the right of the decimal point.

If either operand has a noninteger type, the operands are converted to DECIMAL and divided using DECIMAL arithmetic before converting the result to BIGINT. If the result exceeds BIGINT range, an error occurs.

整数划分。 从除法结果中舍弃小数点右侧的小数部分。

如果任一操作数具有非整数类型,则在将结果转换为BIGINT之前,操作数将转换为DECIMAL并使用DECIMAL算术进行分割。 如果结果超出BIGINT范围,则会发生错误。

实例

SELECT 5 / 2, -5 / 2, 5 / -2, -5 / -2;            # 2.5000  -2.5000 -2.5000 2.5000
SELECT 5 DIV 2, -5 DIV 2, 5 DIV -2, -5 DIV -2;    # 2         -2        -2      2
SELECT 5 DIV 2.0, 5 DIV '2';                      # 2         2
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: