# Ranking Function

Ranking Function

__ROW_NUMBER function__- Derby does not currently allow the named or unnamed window specification to be specified in the OVER() clause, but requires an empty parenthesis. This means the function is evaluated over the entire result set.
- The ROW_NUMBER function cannot currently be used in a WHERE clause.
- Derby does not currently support ORDER BY in sub queries, so there is currently no way to guarantee the order of rows in the SELECT sub query. An optimizer override can be used to force the optimizer to use an index ordered on the desired column(s) if ordering is a firm requirement.

` `

__RANK()__

__function__If two or more rows tie for a rank, each tied rows receives the same rank.

For example, if the two top salespeople have the same SalesYTD value, they are both ranked one. The salesperson with the next highest SalesYTD is ranked number three, because there are two rows that are ranked higher. Therefore, the RANK function does not always return consecutive integers.

__DENSE_RANK()__

__function__If two or more rows tie for a rank in the same partition, each tied rows receives the same rank.

For example, if the two top salespeople have the same SalesYTD value, they are both ranked one. The salesperson with the next highest SalesYTD is ranked number two. This is one more than the number of distinct rows that come before this row. Therefore, the numbers returned by the DENSE_RANK function do not have gaps and always have consecutive ranks.

__NTILE()__

__function__If the number of rows in a partition is not divisible by *integer_expression*, this will cause groups of two sizes that differ by one member. Larger groups come before smaller groups in the order specified by the OVER clause. For example if the total number of rows is 53 and the number of groups is five, the first three groups will have 11 rows and the two remaining groups will have 10 rows each. If on the other hand the total number of rows is divisible by the number of groups, the rows will be evenly distributed among the groups. For example, if the total number of rows is 50, and there are five groups, each bucket will contain 10 rows.

Example are mentioned bellow

**ROW_NUMBER RANK DENSE_RANK NTILE SNAME GRADE**

FROM #EXMAPLE_TABLE

**ROW_NUMBER SNAME GRADE**

**Posted by: MR. JOYDEEP DAS**