Multi-column Rank in SQL Server

There probably is, but I’m slightly new to SQL Server. I need to rank/denserank a dataset, but the ranking is based on 6 columns. What I have at the moment is:

SELECT  col1, col2, col3, col4, col5, col6, col7,
    RANK() OVER(ORDER BY col2 desc) as APPLICANT_RANK 
FROM    myTable

So that works fine, but if there is a tie in col2, then I get two records ranked the same. What I want is if there’s a tie in col2, to see the higher number in col3, then col4, so down the line to col 6.

  • How does SQL Server treat statements inside stored procedures with respect to transactions?
  • Is upsizing MS-Access to MS-SQL-Server version independent?
  • Add row number to this T-SQL query
  • Sql Server Compare Application
  • Is 'console type' of application suitable for my solution? ( C# )
  • Hibernate JDBCConnectionException: could not update
  • Thanks

  • ranking function structure
  • DENSE_RANK() without duplication
  • How to use dense_rank() to achieve real ranking
  • Unable to get desired output using Dense Rank
  • SQL dense_rank function
  • SQL Server window function with conditions (where clause for incremential loading)
  • One Solution collect form web for “Multi-column Rank in SQL Server”

    You can include multiple columns in the order by clause in the rank function, just as you would when ordering the results of a whole query:

    RANK() OVER(
       ORDER BY col2 desc,col3 desc, col4 desc, col5 desc, col6 desc
    ) as APPLICANT_RANK 
    
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.