形式:
函数() Over (PARTITION By 列1,列2,Order By 列3,窗口子句) AS 列别名
窗口子句:(与order by 一起使用)
range/rows between【num】preceding and 【num】 following
order by子句后面没有指定窗口子句,
则默认为:range/rows between unbounded preceding and current row
补充
preceding:往前
following :往后
current row:当前行
unbounded:起点
unbounded precending: 从前面的起点
unbounded following : 到后面的终点
窗口子句举例:
- range/rows between 1 preceding and 2 following
- range/rows between unbounded preceding and current row
- (rows/range) between (unbounded/[num]) precending and ([num] precending/current row/(unbounded /[num]) following)
- (rows/range) between current row and (current row | (unbounded | [num]) following) 当前行到num行之后
- (rows/range) between [num] following and (unbounded | [num]) following 后num行到后num行/终点