SQL windowing function

When using a windowing function encountered a problem: The first row of the packet if the condition was null, turned over () function If the window order by default when the window is the first line to the current line, thus the first case of the emergence of behavioral null
 

If over () is not used, the window is a first order by row to the last row in the group

 

OVER (): Specifies the size of the data window function analysis work, the data window size may change with the change of the line.
CURRENT ROW: current line
n PRECEDING: Previous n rows
n FOLLOWING: next n rows
UNBOUNDED: the starting point, UNBOUNDED PRECEDING represents starting from the front, UNBOUNDED FOLLOWING indicates the end to the back
LAG (col, n, default_val) : To before the n-th line data
LEAD (col, n, default_val) : next n-th line data
NTILE (n): the ordered rows distributed to partition the specified data group, each group numbered, starting at 1, for each row, NTILE returns the number of this row belongs to the group. Note: n must be of type int
Analysis window function is the analysis of the range of data to be processed

When the windowing function over () event of a packet (partition by) clause,

unbounded preceding i.e., the first line refers to a packet in the first row in the table, unbounded following i.e. the last row of the table refers to a packet in the last row;

When the windowing function over () is omitted when the packet (partition by) clause, 

That is unbounded preceding first row is the first row in the table refers, unbounded following i.e. the last row in the table refers to the last row.

而出现order by子句的时候,不一定要有窗口子句,但效果会很不一样,此时的窗口默认是当前组的第一行到当前行!

 

参考https://www.cnblogs.com/cjm123/p/8033892.html

Guess you like

Origin www.cnblogs.com/chungfenghuayu/p/11139945.html