# Window functions

Calculate per-row results across an ordered group.

Source: https://particledb.ai/sql/window-functions/

Calculate per-row results across an ordered group.

## Example

```sql
CREATE TABLE docs_window (id BIGINT PRIMARY KEY, team TEXT, amount BIGINT);
INSERT INTO docs_window VALUES (1, 'support', 10), (2, 'support', 30), (3, 'platform', 20);
```

```sql
SELECT id, team, amount,
       ROW_NUMBER() OVER (PARTITION BY team ORDER BY amount DESC, id) AS rank
FROM docs_window ORDER BY id;
```

## Behavior

A window function retains the input rows. `PARTITION BY` defines independent groups; ordering defines the sequence within each group. Include a tie-breaker when equal values need a stable order. SQL window functions and window Particles have separate support and frame rules.

## Related

[SQL reference](/sql/overview/) · [Application guide](/guides/relational-data/) · [Troubleshooting](/guides/troubleshooting/)
