我試圖創建函數來計算3個值的中值,但得到一些錯誤 - 「功能中的語句無法數據返回到客戶端」SQL Server函數來計算平均
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;
哦,男人......我寫了一個在我上一份工作,從來沒有複製代碼。 – SQLMason