PostgreSQL has a window function called dense_rank()
that returns the rank of the current row, without gaps.
It works the same way that the rank()
function works, but without gaps (the rank()
function includes gaps).
PostgreSQL has a window function called dense_rank()
that returns the rank of the current row, without gaps.
It works the same way that the rank()
function works, but without gaps (the rank()
function includes gaps).
PostgreSQL has a window function called rank()
that returns the rank of the current row, with gaps.
“With gaps” means that it returns the same rank for any ties (i.e. two or more rows with the same value), but then subsequent ranks jump forward to account for the ties.
This means that there’s the potential for noncontiguous rank values. For example it could go 1, 2, 5, etc if several rows are ranked at 2. If there are no ties, then the rank values will be contiguous.
Continue readingIn PostgreSQL, we can use the row_number()
function to get each row’s number within its partition. This allows us to create a column with incrementing row numbers that reset with each new partition.
The row_number()
function is a window function that’s specifically designed to return the number of the current row within its partition, starting at 1 and incrementing sequentially.
MySQL provides us with a wide range of functions for working with JSON documents. Below are four MySQL functions that we can use to get information about JSON values.
Continue readingIn MySQL, ROW_NUMBER()
is a window function that returns the number of the current row within its partition. Numbering starts at 1 and increments sequentially.
In MySQL, the NTILE()
function is a window function that divides a partition into a given number of groups (buckets) and returns the bucket number of the current row within its partition.
In MySQL, the LEAD()
function is a window function that returns the value of a given expression from the row that leads (follows) the current row by a given number of rows within its partition.
Basically, it returns the value from a later row.
Continue readingIn MySQL, the LAG()
function is a window function that returns the value of a given expression from the row that lags (precedes) the current row by a given number of rows within its partition.
Basically, it returns the value from a previous row.
Continue readingIn MySQL, the NTH_VALUE()
function is a window function that returns the value of a given expression from the from the N-th row of the window frame, where N is a number that we specify when calling the function.
In MySQL, the LAST_VALUE()
function is a window function that returns the value of the given expression from the last row of the window frame.