Rank(), DENSE_RANK()和ROW_NUMBER()

Starting from a topic

Which of the following sort function will form a "1,2,2,4,5,5,7" sort of result?

  1. Rank()
  2. DENSE_RANK()
  3. ROW_NUMBER()
  4. All error

 

Resolution:

1.row_number
ROW_NUMBER number will not be repeated continuously during the ranking, also encountered even when two tables 3

perform
SELECT ROW_NUMBER () the OVER (Order by e.salary desc) AS row_num, e.salary
from Employee E
in FIG Results


2.rank
Rank ordering requirements will function the same value as grouped and each number, sort does not continuously
execute
() the OVER (Order by e.salary desc) aS SELECT row_num Rank, e.salary
from Employee E
result:


3.dense_rank
DENSE_RANK sort is continuous, the same value will be divided into a number of different sorting groups each

perform
SELECT DENSE_RANK () the OVER (Order by e.salary desc) AS row_num, e.salary
from Employee E
Results:

This question is so selected DENSE_RANK ()

发布了110 篇原创文章 · 获赞 17 · 访问量 11万+

Guess you like

Origin blog.csdn.net/qq_38890412/article/details/104355270