我有一个包含以下列的数据集
- 城市
- 用户
- 周
- 月
- 收益
理想情况下,我想从percentile_cont(收益,0.5(计算50%(按城市顺序按月份划分,前一行和当前行之间的范围为1(。但是Big查询不支持percentile_cont中的窗口框架。有人能帮我解决这个问题吗。
如果我理解正确,你可以聚合成一个数组,然后unnest:
select t.*,
(select percentile_cont(earning) over ()
from unnest(ar_earnings) earning
limit 1
) as median_2months
from (select t.*,
array_agg(earnings) over (partition by city
order by month
range between 1 preceding and current month
) as ar_earnings
from t
) t;
您没有提供示例数据,但此版本假定month
是表示月份的递增整数。您可能需要根据类型调整range
。