Overview
TheROW_NUMBER()
window function returns the number of the current row within its partition (counting from 1), based on the ORDER BY
expression in the OVER
clause.
It can be used with all data types supported by Oxla.
Syntax
The syntax for this function is as follows:BIGINT
. Rows with equal values for the ORDER BY
expression receive different row numbers nondeterministically.
Parameters
()
: this function takes no arguments but parentheses is required
Examples
For the needs of this section, we will create thewinsales
table that stores details about some sales transactions:
ROW_NUMBER() with ORDER BY
In this example, we will focus on executing theROW_NUMBER()
function with ORDER BY
keyword, assign a row number to each row and order the table by the row number (the results will be sorted after the window function results are applied):
ROW_NUMBER() with ORDER BY and PARTITION BY
In this example, we will focus on executing theROW_NUMBER()
function with ORDER BY
keyword and PARTITION BY
clause, partition the table by seller ID, assign a row number to each row and order the table by the sales ID and row number (the results will be sorted after the window function results are applied):
Time Series: Assigning Sequential Row Numbers by Date
In this example, we will assign a sequential row number to each sale ordered bydateid
: