You are on page 1of 2

ROW_NUMBER

Function : ROW_NUMBER ROW_NUMBER is ANSI SQL-99 Function. ROW_NUMBER is same as RANK except in the event of a tie. ROW_NUMBER does not report duplicate values ,unlike RANK. Following is the result of the RANK function: SELECT EMPLOYEEID,departmentno,salary,RANK() OVER (ORDER BY salary desc) from employee2; Employeeid 124 144 12 11 10 9 8 7 6 5 4 3 2 1 DepartmentNo 200 400 400 300 200 100 400 300 200 100 400 300 200 100 Salary 12345.11 12345.11 12000 11000 10000 9000 8000 7000 6000 5000 4000 3000 2000 1000 Rank(Salary) 1 1 3 4 5 6 7 8 9 10 11 12 13 14

Note that ties produce the same ranking number however their positions are counted against subsequent rankings. Following is the result of the using ROW_NUMBER: SELECT EMPLOYEEID,departmentno,salary,ROW_NUMBER() OVER (ORDER BY salary desc) from employee2; Employeeid 144 DepartmentNo 400 Salary 12345.11 Row_Number() 1

124 12 11 10 9 8 7 6 5 4 3 2 1

200 400 300 200 100 400 300 200 100 400 300 200 100

12345.11 12000 11000 10000 9000 8000 7000 6000 5000 4000 3000 2000 1000

2 3 4 5 6 7 8 9 10 11 12 13 14

Note that even case of tie ROW_NUMBER assigns values sequentially.

at 01:01

You might also like