Collections:
DENSE_RANK() - Density Rank of Sorted Values
How to calculate the density rank of the sorting field expression in the current result set window using the DENSE_RANK() function?
✍: FYIcenter.com
DENSE_RANK() is a MySQL built-in window function that
calculates the density rank of the sorting field expression
in the current result set window.
For example:
SELECT help_topic_id, help_category_id, DENSE_RANK() OVER w FROM mysql.help_topic WINDOW w AS (ORDER BY help_category_id); -- +---------------+------------------+---------------------+ -- | help_topic_id | help_category_id | DENSE_RANK() OVER w | -- +---------------+------------------+---------------------+ -- | 0 | 1 | 1 | -- | 1 | 1 | 1 | -- | 2 | 2 | 2 | -- | 6 | 2 | 2 | -- | 7 | 2 | 2 | -- | 8 | 2 | 2 | -- | 9 | 2 | 2 | -- ... -- +---------------+------------------+---------------------+
Reference information of the DENSE_RANK() function:
DENSE_RANK(): val Returns the density rank of the sorting field expression in the current result set window. Arguments, return value and availability: val: Return value. The density rank of the sorting field. Available since MySQL 8.
Related MySQL functions:
⇒ FIRST_VALUE() - First Value of Result Set Window
⇐ CUME_DIST() - Cumulative Distribution of Sorted Values
2024-09-28, 1092🔥, 0💬
Popular Posts:
How To Break Query Output into Pages in MySQL? If you have a query that returns hundreds of rows, an...
How to download and install the scaled-down database AdventureWorksLT in SQL Server? If you want to ...
Can Date and Time Values Be Converted into Integers in SQL Server Transact-SQL? Can date and time va...
What Happens If the UPDATE Subquery Returns Multiple Rows in MySQL? If a subquery is used in a UPDAT...
What Is the Difference Between GETDATE() and GETUTCDATE() in SQL Server Transact-SQL? The difference...