- 窗口函数的最大特点是有over()关键字
- 函数名(字段名) over(partition by 分组 order by 字段名 [rows between unbounded preceding and current row])
unbounded preceding(分组排序后)起点current row当前行
- 聚合类的窗口函数
- sum() over()
- count/avg/max/min
- 排序类的窗口函数
- row_number,rank,dense_rank
| 排序类 | 含义 | 记忆 |
|---|---|---|
| row_number | 连续不并列编号12345 | 最简单 |
| rank | 不连续编号122446 | --- |
| dense_rank | 连续可并列编号122334 | 最实用 |
- 偏移类的,跨行的
- lag / lead
举例:
- 【了解】first_value/last_value
- 【了解】ntile