Original: "T-SQL Series" New sort function
such as: Row_number, RANK, Dense_rank
All three analysis functions are sorted from 1 in the col1 group
Row_number () is a sort that does not have a duplicate value (even if two days of record equality are not duplicated), it can be used to achieve paging
Dense_rank () is a sequential sort, with two second names still following the third place
RANK () is a jump shoot, two second place is fourth place
Example:
DECLARE @t1 TABLE(SequenceINT, NameVARCHAR( -), scoreINT )INSERT into @t1 SELECT 1 , 'Armor' , 7 UNION All SELECT 2 , 'Armor' , 8 UNION All SELECT 3 , 'Armor' , 8 UNION All SELECT 4 , 'Armor' , 8 UNION All SELECT 5 , 'Armor' , 9 UNION All SELECT 1 , 'b' , Ten UNION All SELECT 2 , 'b' , 6 UNION All SELECT 3 , 'b' , Ten UNION All SELECT 4 , 'b' , 6 UNION All SELECT 5 , 'b' , 8SELECTSequence, Name, Score, row_number () Over(ORDER bySequence, score) asRowNumber1, row_number () Over(ORDER bySequence, ScoreDESC) asRowNumber2, RANK () Over(ORDER byScore) asRnk, Dense_rank () Over(ORDER byScore) asdensernk, NTILE ( the) Over(ORDER byScore) asBuckets from @t1
Result set:
New sort function for "T-SQL Series"