CACrown ArchivesHistory · sources · collections
Menu
Research dossier · General Reference

Window function (SQL)

kind of function in SQL; calculations across a set of table rows that are somehow related to the current row

Cross-disciplinary reference desk with index cards, atlas, dictionary and catalogue
General referenceInterpretive dossier study · Crown Archives visual atlas
Record originEnglish Wikipedia
Text licenseCC BY-SA 4.0
Source revisionFeb 26, 2026
Entity authorityQ24898611
Source-derived summary

In SQL, a window function or analytic function is a function which uses values from one or multiple rows to return a value for each row. (This contrasts with an aggregate function, which returns a single value for multiple rows.) Window functions have an OVER clause; any function without an OVER clause is not a window function, but rather an aggregate or single-row (scalar) function.

Example

As an example, here is a query which uses a window function to compare the salary of each employee with the average salary of their department (example from the PostgreSQL documentation):

Output:

depname | empno | salary | avg

----------+-------+--------+----------------------

develop | 11 | 5200 | 5020.0000000000000000

develop | 7 | 4200 | 5020.0000000000000000

develop | 9 | 4500 | 5020.0000000000000000

develop | 8 | 6000 | 5020.0000000000000000

develop | 10 | 5200 | 5020.0000000000000000

personnel | 5 | 3500 | 3700.0000000000000000

personnel | 2 | 3900 | 3700.0000000000000000

sales | 3 | 4800 | 4866.6666666666666667

sales | 1 | 5000 | 4866.6666666666666667

sales | 4 | 4800 | 4866.6666666666666667

(10 rows)

The PARTITION BY clause groups rows into partitions, and the function is applied to each partition separately. If the PARTITION BY clause is omitted (such as with an empty OVER() clause), then the entire result set is treated as a single partition. For this query, the average salary reported would be the average taken over all rows.

Window functions are evaluated after aggregation (after the GROUP BY clause and non-window aggregate functions, for example).

Syntax

According to the PostgreSQL documentation, a window function has the syntax of one of the following:where window_definition has syntax:frame_clause has the syntax of one of the following:frame_start and frame_end can be UNBOUNDED PRECEDING, offset PRECEDING, CURRENT ROW, offset FOLLOWING, or UNBOUNDED FOLLOWING. frame_exclusion can be EXCLUDE CURRENT ROW, EXCLUDE GROUP, EXCLUDE TIES, or EXCLUDE NO OTHERS.

expression refers to any expression that does not contain a call to a window function.

Notation:

Brackets [] indicate optional clauses

Curly braces {} indicate a set of different possible options, with each option delimited by a vertical bar |

Example

Window functions allow access to data in the records right before and after the current record. A window function defines a frame or window of rows with a given length around the current row, and performs a calculation across the set of data in the window.

NAME |

------------

Aaron| <-- Preceding (unbounded)

Amelia|

Andrew|

James|

Jill|

Johnny| <-- 1st preceding row

Michael| <-- Current row

Nick| <-- 1st following row

Ophelia|

Zach| <-- Following (unbounded)

In the above table, the next query extracts for each row the values of a window with one preceding and one following row:

The result query contains the following values:

| PREV | NAME | NEXT |

|----------|----------|----------|

| (null)| Aaron| Amelia|

| Aaron| Amelia| Andrew|

| Amelia| Andrew| James|

| Andrew| James| Jill|

| James| Jill| Johnny|

| Jill| Johnny| Michael|

| Johnny| Michael| Nick|

| Michael| Nick| Ophelia|

| Nick| Ophelia| Zach|

| Ophelia| Zach| (null)|

History

Window functions were incorporated into the SQL:2003 standard and had functionality expanded in later specifications.

Editorial summary

Begin with the source’s own compact description: “Window function (SQL)” is kind of function in SQL; calculations across a set of table rows that are somehow related to the current row. The dossier treats that line as a proposition to test through Window, function and kind, not as a finished interpretation.

Editorial reviewA practical starting point whose main value is the path it opens into stronger specialist and primary sources. The current lead gives the account dated anchors—2003—that can be checked directly. The selected authority fields contribute no independent date. For this dossier, Window, function and kind is the immediate research focus.
Editorial analysis

Why this record matters

The phrase “kind of function in SQL; calculations across a set of table rows that are somehow related to the current row” supplies a clear boundary for inquiry. It also exposes the unanswered questions: who defined that boundary, when it became stable and which sources sit outside it.

Evidence profile

The citation trail is more important than the brevity of the summary: it shows where individual claims can be examined in context. The source revision retrieved here is dated Feb 26, 2026. The linked authority identifier is Q24898611. None of the 0 selected statements returned an explicit reference. The first chronological checks are 2003.

Critical limits

A concise general-reference account can conceal disagreements about scope, terminology or the weight assigned to individual sources. The lead is largely declarative, so disagreement and counter-evidence require a deliberate search beyond the opening account. Authority statements aid reconciliation but still require their own references, qualifiers and ranks to be checked.

How to read it

Use the entry as an orientation point, then follow its citations and revision history. Names, dates and institutional relationships should be checked against the original record.

Best used for
  • Subject orientation
  • Search vocabulary
  • Locating named sources
Verify next

The closest primary source, responsible institution and strongest cited specialist reference.

Three-step research path

  1. Establish the record: confirm the title “Window function (SQL)”, its source revision and the description used here.
  2. Expand the search: follow Window function (SQL) primary sources, Window function (SQL) archive and Window research across catalogues and specialist indexes.
  3. Test the account: compare the strongest cited source with the responsible institution’s current record and note any disagreement.

Questions for further research

  1. Which source most directly establishes the central claim about “Window function (SQL)”?
  2. Which cited source is closest to the event, object or claim?
  3. What terminology or title could unlock a more precise catalogue search?
Subject index

Search terms from this dossier

Source & attribution

This entry incorporates text from Window function (SQL)” on English Wikipedia. Contributors are listed in the page history. Text is available under the Creative Commons Attribution-ShareAlike 4.0 License. Selected authority identifiers and statements are retrieved from Wikidata under CC0; their references and qualifiers remain part of the verification path.