#MYSQL变量的四则运算以及取模操作
set @x=5,@y=7,@dx=0.1,@dy=5.65;
select @x + @y;
select @x - @y;
select @x * @y;
select @x / @y;#除法注意除数不能为零如果为零返回null,保留四位小数
select @x % @y;
#在浮点数运算时返回的结果会补充很多的0,需要消除这些无用的0
set @result1 = @dx + @dy;
set @result2 = @dx - @dy;
set @result3 = @dx * @dy;
set @result4 = @dx / @dy;
set @result5 = @dx % @dy;
select @result1,@result2,@result3,@result4,@result5;
select ROUND(select @dx / @dy,2);#无法使用
MYSQL变量的四则运算以及取模操作
最新推荐文章于 2024-07-13 10:38:18 发布