- lead 分区的数据往前默认是往前一位
- lag 分区后的数据往后移动
- first_value 取第一个值the second (optional) parameter must be a boolean which is
false
by default. if set to true it skips null values.如果第一个值是null那么如果是true那么就是跳过空值。
- last_value 最后的一个值the second (optional) parameter must be a boolean which is
false
by default. if set to true it skips null values.如果第二个数字是true那么就是,那么就是跳过空值
- 设置窗口的大小
-
(rows | range) between (unbounded | [num]) preceding and ([num] preceding | current row | (unbounded | [num]) following) (rows | range) between current row and (current row | (unbounded | [num]) following) (rows | range) between [num] following and (unbounded | [num]) following
- unbounded preceding是窗口的上边界
- [num] preceding 是窗口的前几条或者是后几条
- current row 是当前的行
- unbounded following 是下边界
- [num] following 是下面几条
- order by 如果没有指定窗口那么就是range between unbounded preceding and current row
- when both order by and window clauses are missing, the window specification defaults to
row between unbounded preceding and unbounded following.
如果不指定order by 和窗口那么就是上边界和下边界
- 使用 rank
-
使用row_number
- 使用 dense_rank
- 使用 cume_dist
- ntile
percent_rank 计算方法为 (rank - 1)/(n- 1)