@@ -82,7 +82,10 @@ current row.
82
82
### ORDER BY clause
83
83
84
84
The ` ORDER BY ` clause inside of the ` OVER ` clause controls the order that the
85
- window function processors rows in each partition.
85
+ window function processes rows in each partition.
86
+ When a window clause contains an ` ORDER BY ` clause, the window frame boundaries
87
+ may be explicit or implicit, limiting a window frame size in both directions
88
+ relative to the current row.
86
89
87
90
> [ !Note]
88
91
> The ` ORDER BY ` clause in an ` OVER ` clause is separate from the ` ORDER BY `
@@ -91,14 +94,49 @@ window function processors rows in each partition.
91
94
92
95
### Frame clause
93
96
94
- The frame clause can be one of the following:
97
+ The frame clause defines window frame boundaries relative to the current row and
98
+ can be one of the following:
95
99
96
100
``` sql
97
101
{ RANGE | ROWS | GROUPS } frame_start
98
102
{ RANGE | ROWS | GROUPS } BETWEEN frame_start AND frame_end
99
103
```
100
104
101
- and ** frame_start** and ** frame_end** can be one of
105
+ #### Frame units
106
+
107
+ ##### RANGE
108
+
109
+ Defines frame boundaries using rows with distinct values for columns specified
110
+ in the [ ` ORDER BY ` clause] ( #order-by-clause ) within a value range relative to
111
+ the current row value.
112
+
113
+ > [ !Important]
114
+ > When using ` RANGE ` frame units, you must include an ` ORDER BY ` clause with
115
+ > _ exactly one column_ .
116
+
117
+ The offset is the difference the between the current row value and surrounding
118
+ row values. ` RANGE ` supports the following offset types:
119
+
120
+ - Numeric
121
+ - String
122
+ - Interval
123
+
124
+ ##### ROWS
125
+
126
+ Defines frame boundaries using row positions relative to the current row.
127
+ The offset is the difference in row position from the current row.
128
+
129
+ ##### GROUPS
130
+
131
+ Defines frame boundaries using row groups.
132
+ Rows with the same values for the columns in the [ ` ORDER BY ` clause] ( #order-by-clause )
133
+ comprise a row group. The offset is the difference in row group position
134
+ relative to the the current row group.
135
+ When using ` GROUPS ` frame units, you must include an ` ORDER BY ` clause.
136
+
137
+ #### Frame boundaries
138
+
139
+ ** frame_start** and ** frame_end** can be one of the following:
102
140
103
141
``` sql
104
142
UNBOUNDED PRECEDING
@@ -108,18 +146,23 @@ offset FOLLOWING
108
146
UNBOUNDED FOLLOWING
109
147
```
110
148
149
+ ##### UNBOUNDED PRECEDING
150
+
151
+
152
+ ##### offset PRECEDING
153
+
111
154
where ** offset** is an non-negative integer.
112
155
113
- ` RANGE ` and ` GROUPS ` modes require an ` ORDER BY ` clause (with ` RANGE ` the ` ORDER BY ` must
114
- specify exactly one column).
156
+ ##### CURRENT ROW
115
157
116
- #### Framing modes
117
158
118
- ##### RANGE
119
159
120
- ##### ROWS
160
+ ##### offset FOLLOWING
161
+
162
+ where ** offset** is an non-negative integer.
163
+
164
+ ##### UNBOUNDED FOLLOWING
121
165
122
- ##### GROUPs
123
166
124
167
125
168
0 commit comments