kblogs-LifeChecker.com | bloghome | subscribe | contact | admin | MainPage
Friday, September 10th  
| comments (325)
Blooming Database Features

Blooming Database Features
SQL Server 2005 New Features

Ranking Functions:

Rank()
Dense_Rank()
NTile()
Row_Number()

Each of these uses the OVER Clause to set up the query.

The coolest of these in my opinion is the NTILE function as it
will divide up a result set into value bands producing an auto-
matic set of categories. In the sample below 4 price ranges would
be created.

SELECT NTILE(4) OVER(Partition BY PRODUCT.NAME ORDER BY PRICE) as
PRICERANGE, PRODUCT.NAME, PRICE
FROM PRODUCT