Skip to content

Commit

Permalink
update sql docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzhao committed Nov 14, 2023
1 parent 95d38dd commit ec6d044
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions docs/basic/4.sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -1547,10 +1547,11 @@ window_function (expression) [null_treatment] OVER (
- FRAME ,表示当前窗口包含哪些数据。滑动窗口有两种指定范围的方式,一种是基于行,一种是基于范围。
- ROWS 选择前后几行,例如 ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING 表示往前 3 行到往后 3 行,一共 7 行数据(或小于 7 行,如果碰到了边界)
- RANGE 选择数据范围,例如 RANGE BETWEEN 3 PRECEDING AND 3 FOLLOWING 表示所有值在 这个范围内的行, 为当前行的值
- RANGE 选择数据范围,例如 RANGE BETWEEN 3 PRECEDING AND 3 FOLLOWING 表示所有值在 [c-3,c+3] 这个范围内的行,c为当前行的值
- ROWS和RANGE的范围边界也可以用 CURRENT ROW
> Frame 定义并非所有窗口函数都适用,比如 ROW_NUMBER()、RANK()、LEAD() 等。这些函数总是应用于整个分区,而非当前 Frame。
Expand Down Expand Up @@ -1730,4 +1731,14 @@ FROM student ) AS top WHERE top.n <2
而 Group By 的做法完全不同:对于各个 Group 它仅仅会保留一行聚合结果。
因为 SQL 及关系代数都是以 multi-set 为基础定义的,结果集本身并没有顺序可言,ORDER BY 仅仅是最终呈现结果的顺序。
因为 SQL 及关系代数都是以 multi-set 为基础定义的,结果集本身并没有顺序可言,ORDER BY 仅仅是最终呈现结果的顺序。
[MySQL官网](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html)
[参考](https://www.cnblogs.com/cjsblog/p/16743807.html)
[参考](https://ericfu.me/sql-window-function/)
[参考](https://www.begtut.com/mysql/mysql-window-functions.html)

0 comments on commit ec6d044

Please sign in to comment.