妙用窗口函数 rows between 、range between

function(x) over(partition by xxx by xx rows between 6 preceding and current row)

另有,from:rows between unbounded preceding and current row等,unbounded ,preceding ,following,current row含义详解_卡奥斯道的博客-CSDN博客

function(x) partition by xxx order by xx rows 6 preceding and 1 following

这两者应该表示的相同的含义,即,

(分区内)前6行至当前行的x执行function(结果按照xx排序)

术语理解:

  • 对于上述示例,也可以不以数字圈定范围,使用unbounded

    unbounded 不受控的(没有边界,不圈定边界的)

    • unbounded preceding 前面所有行
    • unbounded following 后面所有行
  • N preceding 前面N行

  • N following 后面N行

使用示例:

窗口函数rows between 、range between的使用_积一时之步,臻千里之遥程-CSDN博客

其中还有range between --- 按照列值限制窗口大小,如

range between 5 preceding AND 6 following

表示:如果当前值为10的话,就取前后的值在5到16之间的数据。

 

posted on 2021-09-15 16:11  G-Aurora  阅读(219)  评论(0)    收藏  举报