SQLUSA

Microsoft SQL Server 2005 Best Practices

How to find the nth highest price by color?

 

Execute the following script in Query Editor to find the 5th highest price by color:


use AdventureWorks

select Color, ListPrice
from
(select Color,
ListPrice,
SequenceNo=row_number() over (partition by Color order by ListPrice desc)
from Production.Product
where ListPrice > 0)a
where SequenceNo=5

 

SQLUSA - The Best SQL Server 2005 Training in the World
 
 
SQLUSA.com Home Page