Skip to main content
Perform calculations across rows related to the current row.

Supported Functions

Basic Syntax

Use * to include all columns, or specify columns explicitly:

ROW NUMBER

Assign sequential numbers to rows.

With Partition

RANK

Assign rank with gaps for ties.

DENSE RANK

Assign rank without gaps for ties.

Rank Comparison

LAG

Access previous row value.

LEAD

Access next row value.

NTILE

Divide rows into buckets.
Divides users into 4 salary quartiles.

Complete Example

MongoDB Note

MongoDB has limited window function support (5.0+). Complex window functions may require aggregation pipelines.

Limitations

Current implementation supports:
  • PARTITION BY
  • ORDER BY within OVER clause
Not currently supported:
  • Frame clauses (ROWS BETWEEN)
  • FIRST_VALUE, LAST_VALUE
  • Aggregate functions as window functions (SUM() OVER, AVG() OVER)

Next Steps

Insert Data

Create new records

Update Data

Modify existing records