SQL Database Concepts Question:
Download Questions PDF

Do you know what is RANK function?

Answer:

-RANK is one of the Ranking functions which are used to give rank to each row in the result set of a SELECT statement.

-For using this function first specify the function name, followed by the empty parentheses.

-Then specify the OVER function. For this function, you have to pass an ORDER BY clause as an argument. The clause specifies the column(s) that you are going to rank.

For Example

SELECT RANK() OVER(ORDER BY Salary DESC) AS [RowNumber], EmpName, Salary, [Month], [Year] FROM EmpSalary

-In the result you will see that the highest salary got the first rand and the lowest salary got the last rank.

Here the rows with equal salaries will get same ranks.

-Remember that the rank depends on the row's position in the result set, not on the sequential number of the row.

Download Basic SQL Server Interview Questions And Answers PDF

Previous QuestionNext Question
Tell me in brief how SQL server enhances scalability of the database system?Explain the XML support SQL server extends?