SQL的意义下降(相当于Excel的底层函数)
我需要SQL中的东西来模仿excel的FLOOR()函数。 SQL的FLOOR()
函数只需要一个参数,向下舍入到最接近的整数。 但我需要能够select的意义,如在Excel中的FLOOR()
函数。
例如:在Excel中FLOOR(6.03,.125) = 6.00
, FLOOR(6.63,.125) = 6.625
但是到目前为止,我已经尝试了ROUND(6.63,.125)
和= 7.00
和ROUND(6.63,.125,1) = 6.00
有谁知道我可以如何实现我要去的?
Declare @V float = 6.3 Declare @F float = 0.125 Select Floor(@V)+floor((@V-Floor(@V))/@F)*@F
返回
6.25
编辑 – 如果需要UDF
CREATE Function [dbo].[udf-Stat-Round-To](@Value float,@Round float) Returns Float As Begin Return case when @Round=0 then NULL else Floor(@Value)+Floor((@Value-Floor(@Value))/@Round)*@Round end End -- Syntax Select [dbo].[udf-Stat-Round-To](10.13,.125) -- 10.125