PostgreSQL Summary Stats and Window Functions

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/32

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 7:28 PM on 8/10/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

33 Terms

1
New cards

OVER()

Turns a regular function into a window function by defining the set of rows (the window) it operates on.

2
New cards

ROW_NUMBER()

Assigns a unique sequential number to each row.

3
New cards

ORDER BY (in OVER)

Controls the order in which rows are considered by the window function.

4
New cards

PARTITION BY

Divides rows into separate groups so the window function calculates independently within each group.

5
New cards

ROWS / RANGE

Defines a specific frame of rows (e.g., a moving window) for the window function to consider.

6
New cards

LAG()

Retrieves a value from a previous row relative to the current row.

7
New cards

LEAD()

Retrieves a value from a following row relative to the current row.

8
New cards

FIRST_VALUE()

Returns the value from the first row in the window.

9
New cards

LAST_VALUE()

Returns the value from the last row in the current window frame (not necessarily the last row overall).

10
New cards

RANK()

Assigns a rank to each row based on ORDER BY; tied rows share a rank and the next rank is skipped (gaps).

11
New cards

DENSE_RANK()

Assigns a rank to each row based on ORDER BY; tied rows share a rank and no ranks are skipped (no gaps).

12
New cards

NTILE(n)

Divides rows into n roughly equal groups/bins based on ORDER BY.

13
New cards

SUM() OVER()

Calculates a total across a window of rows without collapsing them.

14
New cards

AVG() OVER()

Calculates an average across a window of rows without collapsing them.

15
New cards

MIN() OVER()

Finds the smallest value within a window of rows without collapsing them.

16
New cards

MAX() OVER()

Finds the largest value within a window of rows without collapsing them.

17
New cards

COUNT() OVER()

Counts rows within a window without collapsing them.

18
New cards

Running total

A cumulative calculation that includes rows from the beginning of the window through the current row.

19
New cards

Moving calculation

A calculation that uses only a limited, defined set of nearby rows around the current row (not the whole partition).

20
New cards

Window frame

The specific subset of rows within a window used for the calculation at the current row.

21
New cards

ROWS BETWEEN

Syntax that defines the frame's boundaries using physical row positions relative to the current row.

22
New cards

UNBOUNDED PRECEDING

Frame boundary meaning the start of the partition.

23
New cards

n PRECEDING

Frame boundary meaning n rows before the current row.

24
New cards

CURRENT ROW

Frame boundary meaning the current row.

25
New cards

n FOLLOWING

Frame boundary meaning n rows after the current row.

26
New cards

UNBOUNDED FOLLOWING

Frame boundary meaning the end of the partition.

27
New cards

Default window frame

When ORDER BY is used without an explicit frame

28
New cards

Pivoting

Transforms a table from long/vertical format into wide/horizontal format, turning unique column values into new columns.

29
New cards

CROSSTAB()

PostgreSQL function (from the tablefunc extension) that pivots row data into columns.

30
New cards

ROLLUP()

GROUP BY subclause that generates hierarchical subtotals plus a grand total, based on column order.

31
New cards

CUBE()

GROUP BY subclause that generates all possible combinations of group-level subtotals plus a grand total.

32
New cards

COALESCE()

Returns the first non-NULL value from a list of values; used to replace NULLs with a fallback value.

33
New cards

STRING_AGG()

Combines multiple row values from a column into a single delimited string.