Skip to content

Commit 58b7b4b

Browse files
committed
WIP sql window functions
1 parent 153aa30 commit 58b7b4b

File tree

1 file changed

+52
-9
lines changed
  • content/influxdb3/cloud-dedicated/reference/sql/functions

1 file changed

+52
-9
lines changed

content/influxdb3/cloud-dedicated/reference/sql/functions/window.md

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ current row.
8282
### ORDER BY clause
8383

8484
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.
8689

8790
> [!Note]
8891
> 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.
9194
9295
### Frame clause
9396

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:
9599

96100
```sql
97101
{ RANGE | ROWS | GROUPS } frame_start
98102
{ RANGE | ROWS | GROUPS } BETWEEN frame_start AND frame_end
99103
```
100104

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:
102140

103141
```sql
104142
UNBOUNDED PRECEDING
@@ -108,18 +146,23 @@ offset FOLLOWING
108146
UNBOUNDED FOLLOWING
109147
```
110148

149+
##### UNBOUNDED PRECEDING
150+
151+
152+
##### offset PRECEDING
153+
111154
where **offset** is an non-negative integer.
112155

113-
`RANGE` and `GROUPS` modes require an `ORDER BY` clause (with `RANGE` the `ORDER BY` must
114-
specify exactly one column).
156+
##### CURRENT ROW
115157

116-
#### Framing modes
117158

118-
##### RANGE
119159

120-
##### ROWS
160+
##### offset FOLLOWING
161+
162+
where **offset** is an non-negative integer.
163+
164+
##### UNBOUNDED FOLLOWING
121165

122-
##### GROUPs
123166

124167

125168

0 commit comments

Comments
 (0)