Hi.. I have table of sales reps and products and sales..  I need the top 10 sales persons by product

name             product              sales
john                tv                          100
mary              phone                    50
john               phone                    10
bob                radio                        5
mary             clock                        59

using sql 2005 !
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike EghtebasDatabase and Application DeveloperCommented:
;with cte
Select name, product, sales ,
dense_rank() Over (partition by product Order By sales Desc) As rk
From SalesRepTable Order By name;
Select name, product, sales  From cte
Where rk <= 10;


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JElsterAuthor Commented:
I think the server is 2000

'dense_rank' is not a recognized function name.

Any way to do in SQL2000?
Mike EghtebasDatabase and Application DeveloperCommented:

Select Top 10 name, product, SumSale 
Select name, product, Sum(sales) As SumSale
From MyTable
Group By product, name
) As D ( name, product, SumSale)
Order By product, SumSale Desc, name 

Open in new window

JElsterAuthor Commented:
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions

Any ideas?
Mike EghtebasDatabase and Application DeveloperCommented:
The ORDER BY clause is invalid in views, inline functions, derived tables, and common table expressions unless top(x) and offset fetch is utilized.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.

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.