Skip to content
Advertisement

Why ROW_NUMBER is defined as window function?

I would like to understand better the meaning of window function. The definition says:

A window function performs a calculation across a set of table rows (the window) that are somehow related to the current row

Let’s consider ROW_NUMBER() (the same could be applied for RANK() or DENSE_RANK()). The function simply assign a number to an ordered set of rows. This seems not to follow the above definition: it’s not making a calculation across a set of table rows that are somehow related to the current row, but it’s making a calculation across all result rows.

Can someone please explain that?

Advertisement

Answer

Of course the ranking functions fulfill that definition.

When used without a partition by, the entire table is the “set of table rows”.

The relation to the current row is the value in the current row relative to the other rows.

It follows the definition.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement