Ranking functions return a ranking value for each row in a partition. Depending on the function that is used, some rows might receive the same value as other rows. Ranking functions are nondeterministic.
Transact-SQL provides the following ranking functions:
RANK
NTILE
DENSE_RANK
ROW_NUMBER
The following shows the four ranking functions used in the same query. See each ranking function for function specific examples.
USE AdventureWorks; GO SELECT c.FirstName, c.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 s INNER JOIN Person.Contact c ON s.SalesPersonID = c.ContactID INNER JOIN Person.Address a ON a.AddressID = c.ContactID WHERE TerritoryID IS NOT NULL AND SalesYTD <> 0;
Here is the result set.
Maciej
Dusza
1
4557045
98027
Shelley
Dyck
2
5200475
Linda
Ecoffey
3
3857164
Carla
Eldridge
4
1764939
Carol
Elliott
5
2811013
Jauna
Elson
6
3018725
98055
Michael
Emanuel
7
3189356
Terry
Eminhizer
8
3587378
Gail
Erickson
9
5015682
Mark
10
3827950
Martha
Espinoza
11
1931620
Janeth
Esteves
12
2241204
Twanna
Evans
13
1758386
17 July 2006
MadAbout SQL Server № ???________________________________________select(select 1 as 'data()',2 as 'data()',3 as 'data()',4 as 'data()',5 as 'data()'for xml path(''))x--there is no that metod in this