我正在计算跨栏的13周值的总和,如下所示,我希望计算中位数的方法可以帮助我吗?谢谢!
select a.prod_name,a.week_date,a."13week_sum",
COALESCE(CASE WHEN COUNT(*) over (partition by prod_name order by prod_name,week_date desc rows between 0 preceding and 12 following) = 13 then
sum(a."value") over (partition by prod_name order by prod_name,week_date desc rows between 0 preceding and 12 following)
end)
as "13week_sum"
from vin_table_temp a order by week_date
我正在使用8.2版postgres的青梅。