Finding the top 3 for each the Year

I have a dataset that looks something like this...

Product Name,  Manufacturer,  SaleYear,   GrossSales

I need to find the top three products sold by GrossSales for each year, so it would look like this...

2008
Sony, Product X, $20,000
HP, Product Y, $19,500
Dell, Product Q,  $18,000

2009
Apple, Product J,  $22,150
Dell, Product Q,   $19,200
Sony, Product X,  $14,000

2010...
...top three products....

etc...

So for each year, show the top three products sold by the Gross Revenue...

I believe this uses Row_Number() and Over but not sure of the format.

Thanks!
LVL 39
gdemariaAsked:
Who is Participating?
 
appariConnect With a Mentor Commented:
try this

Select Product Name,  Manufacturer,  SaleYear,   GrossSales
From (Select Product Name,  Manufacturer,  SaleYear,   GrossSales,
row_number() over(partition by SaleYear order by GrossSales desc) rowNum
from tableName) as A
where rowNum <=3
0
 
gdemariaAuthor Commented:
That was it, thanks very much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.