Skip to content

Commit bec7ef0

Browse files
committed
docs: add window function frame specification examples to SQL and DataFrame pages
SQL page: added ROWS BETWEEN examples (rolling average, running total) with the full syntax (UNBOUNDED PRECEDING, N PRECEDING, CURRENT ROW, N FOLLOWING, UNBOUNDED FOLLOWING). DataFrame page: added rolling aggregate example with frame property and documented frame bound values.
1 parent a41d98a commit bec7ef0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

docs/src/content/docs/dataframe-api.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ df.window({
9999

100100
Supported: `row_number`, `rank`, `dense_rank`, `lag`, `lead`, rolling `sum`/`avg`/`min`/`max`/`count` with frame specification.
101101

102+
Rolling aggregates with frame:
103+
104+
```typescript
105+
df.window({
106+
fn: "avg",
107+
column: "amount",
108+
partitionBy: ["region"],
109+
orderBy: [{ column: "created_at", direction: "asc" }],
110+
alias: "rolling_avg",
111+
frame: { type: "rows", start: -2, end: 0 }, // 3-row trailing window
112+
})
113+
```
114+
115+
Frame bounds: numeric offsets (negative = preceding, positive = following), `"unbounded"`, or `"current"`.
116+
102117
## Computed columns
103118

104119
```typescript

docs/src/content/docs/sql.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ SELECT name, LAG(amount, 1) OVER (ORDER BY created_at) AS prev_amount FROM order
101101

102102
`ROW_NUMBER`, `RANK`, `DENSE_RANK`, `LAG`, `LEAD`, and rolling `SUM`/`AVG`/`MIN`/`MAX`/`COUNT` with frame specification.
103103

104+
Frame specification supports `ROWS` and `RANGE` with `UNBOUNDED PRECEDING`, `N PRECEDING`, `CURRENT ROW`, `N FOLLOWING`, `UNBOUNDED FOLLOWING`:
105+
106+
```sql
107+
-- Rolling 3-row average
108+
SELECT name, AVG(amount) OVER (
109+
ORDER BY created_at ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
110+
) AS rolling_avg FROM orders
111+
112+
-- Running total
113+
SELECT name, SUM(amount) OVER (
114+
PARTITION BY region ORDER BY created_at ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
115+
) AS running_total FROM orders
116+
```
117+
104118
### Common Table Expressions (CTEs)
105119

106120
```sql

0 commit comments

Comments
 (0)