This article refers to AdventureWorks2014 of Microsoft.
google ads placeholder
You can download AdventureWorks2014 DB here.
At the following picture there are 4 ranking functions at MS SQL:
1. Row_number – Numbering each row.
2. Rank –ย According to example below when postal code change then the function displays the value of row_number at that position.
3. Dense_Rank – According to example below when postal code change then the function increases.
4. NTile – Divide the results into groups, the example shows division to 4 groups.
![Ranking Ranking Functions](https://wp.flash-jet.com/wp-content/uploads/2014/12/Ranking.png)
You can copy and paste the following text into you MS SQL management studio if order to test it:
SELECTย ย ย ย ย p.firstname, p.lastnameย , Row_number()ย OVERย (ORDERย BYย a.postalcode)ย ASย โrowย numberโย , rank()ย OVERย (ORDERย BYย a.postalcode)ย ย ย ย ย ย ย ASย rankย , dense_rank()ย OVERย (ORDERย BYย a.postalcode)ย ASย โdenseย rankโย , ntile(4)ย OVERย (ORDERย BYย a.postalcode)ย ย ย ย ย ASย quartileย , s.salesytdย , a.postalcode FROMย ย ย ย ย ย ย sales.salespersonย ASย s INNERย JOINย person.personย ย ย ย ย ASย p ONย ย ย ย ย ย ย ย ย s.businessentityidย =ย p.businessentityid INNERย JOINย person.addressย ASย a ONย ย ย ย ย ย ย ย ย a.addressidย =ย p.businessentityid WHEREย ย ย ย ย ย territoryidย ISย NOTย NULL ANDย ย ย ย ย ย ย ย salesytdย <>ย 0;
![Ranking Functions](http://social.technet.microsoft.com/wiki/resized-image.ashx/__size/550x0/__key/CommunityServer-Wikis-Components-Files/00-00-00-00-05/0310.SQLServerLogo.png)