Concept
sqlite add tag
Community
A "window function" calculates a value based on input from more than one row (like an aggregate function). The result is produced without grouping the source rows (**unlike** an aggregate function).

The input row set for the calculation, or "window", is defined by an `OVER` clause. If, and only if, an `OVER` clause is present, then the function is a window function. Otherwise it is an ordinary function (either aggregate or scalar).


[![Railroad](/image?hash=97e74e1bb698bfaa457fa807e076acfa78f9465ce32c64f398da1a1915c42dc9)](https://tabatkins.github.io/railroad-diagrams/generator.html#Diagram(%0A%20%20NonTerminal('function')%0A%20%2COptional(NonTerminal('filter-clause')%2C'skip')%0A%20%2CTerminal('OVER')%0A%20%2CTerminal('(')%0A%20%2COptional(Sequence(Terminal('PARTITION')%2CTerminal('BY')%2COneOrMore(NonTerminal('expr')%2C'%2C'))%2C'skip')%0A%20%2COptional(Sequence(Terminal('ORDER')%2CTerminal('BY')%2COneOrMore(NonTerminal('expr')%2C'%2C'))%2C'skip')%0A%20%2COptional(NonTerminal('frame-specification')%2C'skip')%0A%20%2CTerminal(')')%0A)%0A%0A)

* The optional `PARTITION BY` clause defines the set of rows to use as input (if not specified all rows are used as input).
* The optional `ORDER BY` clause defines the order in which the rows are input to the function.

# See Also

* [SQLite Documentation](https://www.sqlite.org/windowfunctions.html)
* [SQLite Tutorial](https://www.sqlitetutorial.net/sqlite-window-functions/)

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.