我想在多个连续的选择中使用窗口函数,但是似乎只有第一个能够利用分区。
来源表如下:
create table mytable
(
myvar int
)
partitioned by (ut string, year string, month string, day string);
以下是我用来查询mytable的代码示例:
select *,
first_value(next_var_value ignore nulls) over (partition by ut order by year,month,day rows between 1 following and unbounded following)
as next_2_value
from(
select ut, year,month,day, myvar,
first_value(myvar ignore nulls) over (partition by ut order by year,month,day rows between 1 following and unbounded following)
as next_var_value
from mytable
)a;
next_var_value的窗口函数似乎能够利用mytable分区,但是第二个选择窗口函数(next_2_value)不能。
我可以为每个选择创建一个新表,但是,我不想这样做。