oracle generate duplicate sequence numbers in the duplicate data Table

   oracle generating the data sequence number in the table: 

   Generally a long way:

The SELECT 
    ROW_NUMBER () the OVER ( the ORDER  BY english DESC ) seq, 
    name , 
    Sex , 
    english the FROM 
   'English scores table'

 

  But products says Xiao Ming and 90 points are red, what red is the second ah, the product desired effect is red Xiao Ming tied for first

The results so long:

  

 

 

 

 

 

 

 

 

 

 

Sql long last resolve this:

The SELECT 
    DENSE_RANK () the OVER ( the ORDER  BY  COUNT ( * ) DESC ) seq, 
    name, 
        Sex, 
        english 
the FROM 
    ' English scores table '

    

The last offer Baidu's explanation:

row_numbe must use clause selection over a column to sort the use of r is very extensive, it is best to use the sort, it will generate a query sequence number out of each row are sequentially sorted and does not repeat, when attention function using row_number in order to generate numbers.

rank function for ranking partition returns a result set for each row, the ranking is the number of rows before the relevant row rank plus one. Simply rank function is to check out the record ranking with row_number function is different, taking into account the rank function over the same sort field value clause case, if a function to generate sequence number rank, sort field over clause value of the same number are the same, the rear field value is not the same sequence number will skip arranged for a number of the same rank, that is, the position number plus one before the relevant row, as will be appreciated the production number based on the current number of records, the latter records and so on.

dense_rank similar function to rank function function, dense_rank function when the production number is continuous, and the rank number of the function may not be generated continuously. dense_rank function appears when the same rank, the same will not skipped ranking number, rank value immediately before the last rank value. Within each group, rank () is the jump order, the next step is the first time there are two third, dense_rank () is a continuous sort, still followed by second place when there are two first place.

Guess you like

Origin www.cnblogs.com/jiangde/p/11597895.html