我正在尝试创建函数来计算 3 个值的中位数,但几乎没有错误-“函数内的 Stmt 无法将数据返回给客户端”
CREATE FUNCTION median(@value1 float,@value2 float,@value3 float)
RETURNS float
AS
BEGIN
DECLARE @ret float;
DECLARE @CNT int = 3;
select cast(avg(tb1.val*1.0) as float) as @ret
from
(select
val, ROW_NUMBER() over (order by val) as rid
from
(select @value1 val
union
select @value2 val
union
select @value3 val) TB1
where tb1.rid in ((@cnt + 1) / 2, (@cnt + 2) / 2)
return @ret;
end;