求一sql ,关于类似C#中的math.max解决办法
求一sql ,关于类似C#中的math.max
我现在需要修改数据表一个字段的值,
将一个表中的num字段都乘以10,同时这个字段的值不能超过100,不知道怎么做,
在sql中没有math.min函数,貌似是取整个列中的最小值,所以不行。。。。。
------解决方案--------------------
我现在需要修改数据表一个字段的值,
- SQL code
update test set num = replace([num], [num],[color=#FF0000] [num]*10[/color])
将一个表中的num字段都乘以10,同时这个字段的值不能超过100,不知道怎么做,
在sql中没有math.min函数,貌似是取整个列中的最小值,所以不行。。。。。
------解决方案--------------------
- SQL code
declare @test table (num numeric(5,1)) insert into @test select 8 union all select 7.2 union all select 6 union all select 21 union all select 7 union all select 12 update @test set num=case when num*10>100 then 100 else num*10 end select * from @test /* num --------------------------------------- 80.0 72.0 60.0 100.0 70.0 100.0 */