【发布时间】:2020-02-13 19:16:06
【问题描述】:
在此如何用中位数计算替换 avg?
select *
, coalesce(val, avg(val) over (order by t rows between 3 preceding and 1 preceding)) as fixed
from (
values
(1, 10),
(2, NULL),
(3, 10),
(4, 15),
(5, 11),
(6, NULL),
(7, NULL),
(8, NULL),
(9, NULL)
) as test(t, val)
;
这有合法的版本吗?
percentile_cont(0.5) within group(order by val) over (order by t rows between 3 preceding and 1 preceding)
【问题讨论】:
-
这是我能找到的最接近的答案,但不一样:stackoverflow.com/questions/39683330/…
标签: sql postgresql window-functions median