Collections:
RANK() - Vale Rank of Sorted Values
How to calculate the value rank of the sorting field expression in the current result set window using the RANK() function?
✍: FYIcenter.com
RANK(n) is a MySQL built-in window function that calculates the value rank of the sorting field expression in the current result set window. For example:
SELECT help_topic_id AS tic, help_category_id AS cid, RANK() OVER w, DENSE_RANK() OVER w FROM mysql.help_topic WINDOW w AS (ORDER BY help_category_id); -- +-----+-----+---------------+---------------------+ -- | tic | cid | RANK() OVER w | DENSE_RANK() OVER w | -- +-----+-----+---------------+---------------------+ -- | 0 | 1 | 1 | 1 | -- | 1 | 1 | 1 | 1 | -- | 2 | 2 | 3 | 2 | -- | 6 | 2 | 3 | 2 | -- | 7 | 2 | 3 | 2 | -- | 8 | 2 | 3 | 2 | -- | 9 | 2 | 3 | 2 | -- | 10 | 2 | 3 | 2 | -- ... -- +-----+-----+---------------+---------------------+
Reference information of the RANK() function:
RANK(): val Calculates the value rank of the sorting field expression in the current result set window. Arguments, return value and availability: val: Return value. The value of the sorting field. Available since MySQL 8.
Related MySQL functions:
⇒ ROW_NUMBER() - Row Position in Result Set Window
⇐ PERCENT_RANK() - Rank Percentage of Sorted Values
2023-12-19, 227🔥, 0💬
Popular Posts:
How To Get a List of All Tables with "sys.tables" View in SQL Server? If you want to see the table y...
How To End a Stored Procedure Properly in SQL Server Transact-SQL? Where the end of the "CREATE PROC...
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for ma...
What Happens If the UPDATE Subquery Returns Multiple Rows in MySQL? If a subquery is used in a UPDAT...
How To Connect the Oracle Server as SYSDBA in Oracle? This is Step 4. The best way to connect to the...